【发布时间】:2015-09-02 01:35:30
【问题描述】:
最近我开始使用模板。 我只是转储一个编译错误。
我有一个类模板Foo,它采用布尔值B 作为模板参数。
我想交朋友,在 Foo 的实例中,模板参数为 b,Foo 的另一个实例的构造函数,参数为 !b,代码如下:
template<bool B>
class Foo
{
public:
Foo(Foo<!B>&);
private:
friend Foo<!B>::Foo(Foo<B>&);
};
编译器返回这些错误:
test.cpp:22:18: error: C++ requires a type specifier for all declarations
friend Foo<!B>::Foo(Foo<B>&);
~~~~~~ ^
test.cpp:22:18: error: constructor cannot have a return type
friend Foo<!B>::Foo(Foo<B>&);
^~~
2 errors generated.
我使用以下命令编译它:Windows 上的clang++ -std=c++11 foo.cpp。
我真的不明白如何使它工作,感谢任何帮助了解问题所在。
【问题讨论】: