저는 C++을 처음 사용합니다. 나는 아래의 코드를 컴파일 할 때이 오류오류 : 기본 클래스 생성자가 부모 클래스 생성자를 명시 적으로 초기화해야합니다.
constructor for 'child' must explicitly initialize the base class 'parent' which does not have a default constructor child::child(int a) {
내 수업
#include<iostream>
using namespace std;
class parent
{
public :
int x;
parent(int a);
int getX();
};
parent::parent(int a)
{
x = a;
}
int parent::getX()
{
return x;
}
class child : public parent
{
public:
child(int a);
};
child::child(int a)
{
x = a;
}
int main(int n , char *argv[])
{
}
가 왜이 오류를 얻고있다 얻을? 어떻게 해결할 수 있습니까? 미리 감사드립니다.
이 좋은 해결책이 아니다. 'parent '가 인스턴스화 될 수없는 추상 클래스이지만 괜찮은 클래스일지도 모르겠다. – Rook