【发布时间】:2013-02-22 21:37:43
【问题描述】:
我收到以下错误:
circleType.cpp||In function 'std::ostream& operator<<(std::ostream&, circleType&)':|
circleType.cpp|48|error: 'getRadius' was not declared in this scope|
circleType.cpp|49|error: 'circumference' was not declared in this scope|
circleType.cpp|50|error: 'area' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|
在这里发现错误:
ostream& operator <<(ostream& outs, circleType& circle1)
{
outs << "radius: " << getRadius() << endl
<< "circumference: " << circumference() << endl
<< "area: " << area() << endl;
return outs;
}
以圆周函数为例:
double circleType::circumference()
{
return (radius*2*pi);
}
头文件:
class circleType
{
public:
circleType(); // færibreytulaus smiður
circleType(double the_radius);
double getRadius();
void setRadius(double the_radius);
double area();
double circumference();
friend ostream& operator <<(ostream& outs, circleType& );
private:
double radius;
};
主要:
circleType circle1(3.0);
cout << "circle1:" << endl;
cout << "--------" << endl;
cout << circle1 << endl;
所有标题都包含在任何地方。我仍然对重载功能有点困惑,任何帮助。
【问题讨论】:
标签: c++ class compiler-errors overloading