主题:请教一下,为什么这里的重载函数不能用
#include<iostream>
using namespace std;
class DataType{
private:
enum{
integer,
character,
floating_point
}type;
union{
char c;
int i;
float f;
};
public:
//函数重载
DataType(char cc){
type=character;
c=cc;
}
DataType(int ii){
type=integer;
i=ii;
}
DataType(float ff){
type=floating_point;
f=ff;
}
void print();
};
void DataType::print(){
switch(type){
case integer:
cout<<"整型"<<i<<endl;
break;
case character:
cout<<"字符型"<<c<<endl;
break;
case floating_point:
cout<<"浮点型"<<f<<endl;
break;
}
}
int main(){
DataType a(144),b('c'),c(3.689);//error C2668: 'DataType::DataType' : ambiguous call to overloaded function
a.print();
b.print();
c.print();
return 0;
}
using namespace std;
class DataType{
private:
enum{
integer,
character,
floating_point
}type;
union{
char c;
int i;
float f;
};
public:
//函数重载
DataType(char cc){
type=character;
c=cc;
}
DataType(int ii){
type=integer;
i=ii;
}
DataType(float ff){
type=floating_point;
f=ff;
}
void print();
};
void DataType::print(){
switch(type){
case integer:
cout<<"整型"<<i<<endl;
break;
case character:
cout<<"字符型"<<c<<endl;
break;
case floating_point:
cout<<"浮点型"<<f<<endl;
break;
}
}
int main(){
DataType a(144),b('c'),c(3.689);//error C2668: 'DataType::DataType' : ambiguous call to overloaded function
a.print();
b.print();
c.print();
return 0;
}