class Example {
//...
static auto make = []() -> std::shared_ptr {
return std::make_shared(Params::EchoBufferSize);
};
static auto recycle = [](std::shared_ptr o) {
//nothing for now
};
recycle::shared_pool receivePool(make, recycler);
};
但我得到了
In file included from /home/project/AIPTCPClient.cpp:57:0:
/home/project/AIPTCPClient.h:312:57: error: 'make' is not a type
recycle::shared_pool receivePool(make, recycler);
^~~~
/home/project/AIPTCPClient.h:312:63: error: 'recycler' is not a type
recycle::shared_pool receivePool(make, recycler);
^~~~~~~~
正如您在shared_pool中看到的,它需要两个函数,这就是我传递lambda的原因。但是C++抱怨说它们应该是类型。我还是不明白。为什么构造函数需要类型而不是对象?
回答开始:得票数 4Default member initializer (由于C++11)仅支持带括号列表初始值设定项和等号初始值设定项,但不支持圆括号初始值设定项;因此请更改
recycle::shared_pool receivePool(make, recycler);
至
recycle::shared_pool receivePool{make, recycler};
或
recycle::shared_pool receivePool = recycle::shared_pool(make, recycler);
总结
以上是真正的电脑专家为你收集整理的错误:“x”不是x是构造函数参数的类型的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得真正的电脑专家网站内容还不错,欢迎将真正的电脑专家推荐给好友。
有话要说...