#include<iostream>
using namespace std;
int flag = 0;
class DataType {
enum {
character,
integer,
floating_point
}vartype;
union {
char c;
int i;
float f;
};
public:
DataType(int aa) {
vartype = integer;
i = aa;
}
DateType(float bb) {
vartype = floating_point;
f = bb;
}
DateType(char cc) {
vartype = character;
c = cc;
}
void print();
~DataType();
};
void DataType::print()
{
switch (vartype) {
case integer:
cout << "整型:" << i << endl;
break;
case floating_point:
cout << "浮点型:" << f << endl;
break;
case character:
cout << "字符型:" << c << endl;
break;
}
}
//DataType::~DataType() {};
int main()
{
DataType a(22), b(3.14), c('s');
a.print();
b.print();
c.print();
}
在DataType的类中,有三个参数不同的构造函数,编译报错:
错误 C4430 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
咋错了啊?用的是VS2022