[英]Call constructor of member object
I try to implement the amySQL, AND I want to intialize this connector intro test function. 我尝试实现amySQL,并且想初始化该连接器简介测试功能。
class Foo
{
public:
void Test();
protected:
amy::connector mgr;
private:
asio::io_service m;
};
void Foo::Test()
{
mgr(m);
}
However when i want to compile i get this error: 但是,当我要编译时,出现此错误:
error: no match for call to '(amy::connector {aka amy::basic_connector<amy::mysql_service>}) (asio::io_service&)'
mgr(m);
What i do wrong here? 我在这里做错了什么? Repository to amy sql https://github.com/liancheng/amy
到amy sql的存储库https://github.com/liancheng/amy
You need to initialize the mgr
member inside the Foo
class constructor, not in the Test()
class method: 您需要在
Foo
类构造函数中而不是在Test()
类方法中初始化mgr
成员:
class Foo
{
public:
Foo();
void Test();
private:
asio::io_service m;
protected:
amy::connector mgr;
};
Foo::Foo() : mgr(m) // <-- initialize here!
{
}
void Foo::Test()
{
// use mgr here as needed...
}
您可以在类构造函数的初始化列表中初始化成员
Foo::Foo() : mgr(m) {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.