C++ 类函数重载错误。强制类型转换错误 。
#include<iostream>usingnamespacestd;classcountt{private:intone;doubletwo;public:doubl...
#include <iostream>
using namespace std;
class countt
{
private:
int one;
double two;
public:
double operator + (double &t);
countt(double tw): two(tw){}
};
double countt::operator +( double &t)
{
double f;
f = two + t;
return f;
}
int main()
{
countt aa(2.5);
double c;
c = aa + 2.7;
cout << c << endl;
while(2);
return 0;
}
// 应该要怎样才能正确地强制转换呢? 展开
using namespace std;
class countt
{
private:
int one;
double two;
public:
double operator + (double &t);
countt(double tw): two(tw){}
};
double countt::operator +( double &t)
{
double f;
f = two + t;
return f;
}
int main()
{
countt aa(2.5);
double c;
c = aa + 2.7;
cout << c << endl;
while(2);
return 0;
}
// 应该要怎样才能正确地强制转换呢? 展开
1个回答
展开全部
#include <iostream>
using namespace std;
class countt
{
private:
int one;
double two;
public:
double operator + (double t); // t不能带引用
countt(double tw): two(tw){}
};
double countt::operator +( double t) // t不能带引用
{
double f;
f = two + t;
return f;
}
int main()
{
countt aa(2.5);
double c;
c = aa + 2.7;
cout << c << endl;
while(2);
return 0;
}
using namespace std;
class countt
{
private:
int one;
double two;
public:
double operator + (double t); // t不能带引用
countt(double tw): two(tw){}
};
double countt::operator +( double t) // t不能带引用
{
double f;
f = two + t;
return f;
}
int main()
{
countt aa(2.5);
double c;
c = aa + 2.7;
cout << c << endl;
while(2);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询