我在初始化对象时遇到问题.以下是一段代码,
#include <iostream>
#include <conio.h>
using namespace std;
class Base
{
public:
Base(int a)
{
m_a = a;
}
private:
int m_a;
};
class Derived:public Base
{
public:
Derived(char a)
{
m_a = a;
}
private:
char m_a;
};
void main()
{
_getch();
}
Run Code Online (Sandbox Code Playgroud)
编译上面的代码会出现以下错误,错误C2512:'Base':没有合适的默认构造函数可用
我知道由于派生类和基类都只有参数化构造函数,我需要在派生类构造函数中初始化基类对象.但我不知道该怎么做.谁能告诉我上面的代码有什么问题?
| 归档时间: |
|
| 查看次数: |
1049 次 |
| 最近记录: |