请看这个代码
class Bond
{
public:
Bond(int payments_per_year, int period_lengths_in_months);
Bond() = default;
private:
const int payments_per_year;
const int period_length_in_months;
};
int main()
{
Bond b; // Error here
}
Run Code Online (Sandbox Code Playgroud)
在尝试编译时,我收到一个错误:
错误C2280:'Bond :: Bond(void)':尝试引用已删除的函数".
因为我已经添加了默认构造函数,所以这不是"3规则"违规.
编译器为什么不识别Bond() = default;?
考虑一个模板类
template<class T>
class Foo
{
};
Run Code Online (Sandbox Code Playgroud)
我可以写一个简单的专业化
template<>
class Foo<int>
{
};
Run Code Online (Sandbox Code Playgroud)
我有一种情况,我想使用模板类专门化Foo,详细使用bool作为编译时标志:
template<>
class Foo<int, bool> // Clearly not the correct notation.
{
}
Run Code Online (Sandbox Code Playgroud)
用途包括Foo <1,true>和Foo <1,false>.
什么是类名的正确表示法,我在其中标记了"显然不是正确的表示法".
我编写了C++ 11标准.