0x00 引言
想注册一个公众号,我好像文笔不是很好,我有很多内容可写,时间和文笔去哪儿找。
Pytorch 1.0 才发布不久,但整个机器学习领域很成熟了,可以弥补不足。
0x01 函数指针
struct IDataReader
{
virtual void ReadCallbackFunc(std::string topicName) = 0;
};
class Subscriber
{
public:
Subscriber();
~Subscriber();
bool SetCallback(IDataReader* iReader)
{
_process = iReader;
_process("callback");
return true;
}
private:
IDataReader * _process;
};
0x02 Cpp调用
具体代码如下:
class Example_Subscriber : IDataReader
{
public:
Example_Subscriber() {};
~Example_Subscriber();
void example_subscriber_main();
void CallbackFunc(std::string topicName);
private:
Subscriber * subscriberPtr;
};
Example_Subscriber::Example_Subscriber()
{
subscriberPtr = new Subscriber();
}
Example_Subscriber::~Example_Subscriber()
{
delete subscriberPtr;
}
void Example_Subscriber::example_subscriber_main()
{
subscriberPtr->SetCallback(this);
}
void Example_Subscriber::CallbackFunc(std::string topicName)
{
printf(topicName);
}
int main()
{
Example_Subscriber * sub = new Example_Subscriber();
sub->subscriber_main();
}
0x03 UPDATE
2019-03-01