过载-不在范围内
Overload - not in scope
我得到这些错误:
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;
};
Main:
circleType circle1(3.0);
cout << "circle1:" << endl;
cout << "--------" << endl;
cout << circle1 << endl;
所有页眉都包含在各处。我仍然有点困惑的过载功能,任何帮助通知。
您没有调用输入对象(circle1
)上的成员函数;相反,您正试图调用一些不存在的具有相同名称的全局函数(请注意,friend
函数不是它的朋友类的成员函数,而是一个已被授予访问类内部的自由非成员函数)。
要解决此问题,请更改过载operator <<
的定义,如下所示:
ostream& operator << (ostream& outs, circleType& circle1)
{
outs << "radius: " << circle1.getRadius() << endl
<< "circumference: " << circl1.circumference() << endl
<< "area: " << circle1.area() << endl;
return outs;
}
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 错误:未在此范围内声明'reverse'
- 并行用于C++17中数组索引范围内的循环
- 求出有多少个数字是完美平方,而sqrt()是L,R范围内的素数
- 不计算一个范围内的完美数
- 错误:"imread"未在此范围内声明
- 我在范围内未声明的错误类有问题
- 如何在cpp中使用地图显示给定日期范围内(在下面的问题中)的费率?
- 我有一个数组,我想输入一个范围,然后找到范围内所有偶数的总和?
- 未在此范围内声明错误 'xy'
- 在C++中使用变量而不是"#define"来指定数组大小是不是一种糟糕的做法?(C错误:在文件范围内
- 命名空间范围内的外部 - GCC vs clang vs msvc
- 如何改进一堆在已知值范围内评估变量的 else-if 条件?
- 如何仅使用 While 循环在给定范围内找到可被 7 整除的计数整数
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- 查找给定范围内最长连续 1 的频率
- "Main"已在当前范围内声明
- 为什么C 不支持范围内的过载
- 过载-不在范围内