相关疑难解决方法(0)

继承构造函数

为什么这段代码:

class A
{
    public: 
        explicit A(int x) {}
};

class B: public A
{
};

int main(void)
{
    B *b = new B(5);
    delete b;
}
Run Code Online (Sandbox Code Playgroud)

导致这些错误:

main.cpp: In function ‘int main()’:
main.cpp:13: error: no matching function for call to ‘B::B(int)’
main.cpp:8: note: candidates are: B::B()
main.cpp:8: note:                 B::B(const B&)

B不应该继承A的构造函数吗?

(这是使用gcc)

c++ inheritance gcc constructor

199
推荐指数
5
解决办法
19万
查看次数

什么是构造函数继承?

在C++ 11中,继承构造函数意味着什么?如果它是我认为的(基类构造函数被带入派生类的范围),它对我的​​代码有什么影响?这样的功能有哪些应用?

c++ inheritance constructor c++11

65
推荐指数
1
解决办法
3万
查看次数

字符串文字不允许作为非类型模板参数

以下引用来自Addison Wesley的C++模板.有人可以帮助我用简单的英语/外行人的术语来理解它的要点吗?

因为字符串文字是具有内部链接的对象(两个字符串文字具有相同的值但在不同的模块中是不同的对象),所以您不能将它们用作模板参数:

c++ templates string-literals

37
推荐指数
3
解决办法
5784
查看次数

标签 统计

c++ ×3

constructor ×2

inheritance ×2

c++11 ×1

gcc ×1

string-literals ×1

templates ×1