I was practicing constructors. Below is the code which I was practicing but got an error that
"reference to distance is ambiguous" I could not identify my error, Please help me. I have been trying that .
#include <iostream>
#include <conio.h>
using namespace std;
//distance
class distance
{
public:
distance(int met, int cen);
distance(int met);
void display();
private:
int meters;
int centimeters;
};
distance::distance(int met, int cen){
cout<<"Object have been initialized and assigned the values"<<endl;
meters=met;
centimeters=cen;
}
distance::distance(int met){
meters=met;
cout<<"One member has been initialized "<<endl;
cout<<"Please enter the distance in centimeters"<<endl;
cin>>centimeters;
}
void distance::display(){
cout<<"The distance in centimeters is "<<centimeters<<endl;
cout<<"The distance in meters is "<<meters<<endl;
}
int main(){
//explicit call
distance a=distance(10,20);
a.display();
int c,m;
cout<<"Enter the distance in centimeters and meters"<<endl;
cin>>c>>m;
//implicit call
distance dist(c,m);
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…