[英]Finding the object for which the constructor will be called while converting one class type to another class type
#include<iostream>
using namespace std;
class meter
{
private:
float m;
public:
meter()
{
m=0.0;
}
meter(float m1)
{
m=m1;
}
void display()
{
cout<<"the equivalient meter is "<<m<<endl;
}
};
class feet
{
private:
float f;
public:
void input()
{
cout<<"enter the value of feet"<<endl;
cin>>f;
}
operator meter()
{
float m1=f*0.3048;
return(meter(m1)); //line of interest
}
};
int main()
{
feet f2;
meter m2;
f2.input();
m2=f2; //type conversion call
m2.display();
return(0);
}
在上述代码中,在感兴趣的行中; “return(meter(m1))”调用构造函数meter(float m1),object? 我尝试一步一步地调试和观察,仍然无法弄清楚,我观察到没有创建新的 object。 是否适用于 object m2?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.