小编Sas*_*ram的帖子

为什么我的编译器不识别"Bond()= default;"?

请看这个代码

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;

c++ c++11

39
推荐指数
3
解决办法
2816
查看次数

如何使用模板专门化模板?

考虑一个模板类

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标准.

c++ templates c++11

0
推荐指数
1
解决办法
80
查看次数

标签 统计

c++ ×2

c++11 ×2

templates ×1