【发布时间】:2016-07-06 17:19:53
【问题描述】:
我有一个带有基类和派生类的应用程序。我需要在派生类中有一个基类文件,但是在初始化它时遇到了一些问题。代码如下:
#include <iostream>
using namespace std;
class X
{
public :
X( int x ) { }
} ;
class Y : public X
{
X x ;
Y* y ;
Y( int a ) : x( a ) { }
} ;
int main()
{
return 0;
}
还有错误:
/tmp/test.cpp||In constructor ‘Y::Y(int)’:|
/tmp/test.cpp|14|error: no matching function for call to ‘X::X()’|
/tmp/test.cpp|14|note: candidates are:|
/tmp/test.cpp|7|note: X::X(int)|
/tmp/test.cpp|7|note: candidate expects 1 argument, 0 provided|
/tmp/test.cpp|4|note: X::X(const X&)|
/tmp/test.cpp|4|note: candidate expects 1 argument, 0 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
【问题讨论】:
标签: c++ inheritance initializer-list