错误:"x"不是其中x是构造函数参数的类型 [英] error: 'x' is not a type where x is constructor argument

查看:53
本文介绍了错误:"x"不是其中x是构造函数参数的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Example {
    //...
    static auto make = []() -> std::shared_ptr<receiveObject> {
        return std::make_shared<receiveObject>(Params::EchoBufferSize);
    };

    static auto recycle = [](std::shared_ptr<receiveObject> o) {
        //nothing for now
    };
    recycle::shared_pool<receiveObject> 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<receiveObject> receivePool(make, recycler);
                                                         ^~~~
/home/project/AIPTCPClient.h:312:63: error: 'recycler' is not a type
         recycle::shared_pool<receiveObject> receivePool(make, recycler);
                                                               ^~~~~~~~

您可以在 shared_pool ,它需要两个函数,这就是为什么我要传递lambda.但是C ++抱怨说它们应该是类型.我不明白为什么构造函数需要类型而不是对象?

As you can see in shared_pool, it requires two funcions, that's why I pass my lambdas. But C++ complain that they should be types. I don't get it. Why a constructor would need a type instead of an object?

推荐答案

默认成员初始值设定项(自C ++ 11起)仅支持括号列表初始值设定项和等号初始值设定项,但不对括号进行初始化.所以改变

Default member initializer (since C++11) only supports braced-list initializer and equal-sign initializer, but not parentheses initializer; so change

recycle::shared_pool<receiveObject> receivePool(make, recycler);

recycle::shared_pool<receiveObject> receivePool{make, recycler};

recycle::shared_pool<receiveObject> receivePool = recycle::shared_pool<receiveObject>(make, recycler);

这篇关于错误:"x"不是其中x是构造函数参数的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆