C++编绎问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:22:51
Compiling...
fraction.cpp
E:\工具软件\VC\MSDev98\MyProjects\fraction\fraction.cpp(69) : error C2143: syntax error : missing ';' before 'tag::id'
E:\工具软件\VC\MSDev98\MyProjects\fraction\fraction.cpp(69) : fatal error C1004: unexpected end of file found
这两个错误对应的行是
Cfraction Cfraction::operator +(int a) Cfraction::operator +(int a)
{
return Cfraction temp(below*a+above,below);
}
Cfraction是一个类,这个是哪的错呢
怪了,怎么多了个“Cfraction Cfraction::operator +(int a)”

这么改试试
Cfraction Cfraction::operator +(int a)
{
Cfraction tmp;
tmp=new Cfraction(below*a+above,below);
return tmp;
}

出错原因估计是你的return Cfraction temp(below*a+above,below);这一句
tmp这里是个局部变量,返回tmp类后函数马上就会把类tmp销毁,致使后面的调用会失败,如果用new分配空间后就不会被销毁。
但是这个问题在一般不会发生在编译阶段,你还得找找前面代码的问题。