用于打印的返回点,已使用错误
Return Point for printing, inherritance used
- 这个原始问题得到了解决,在评论中是后来出现的问题;
我如何使用GeoObject::printInfo()使Layer::printInfo()打印信息?
关于结构:Marker来自类GeoObject。在GeoObject中,包括文件Point.h。存储在类Point中的信息是int long和int lat(经度,坐标点的纬度)。
现在,我试图通过覆盖虚拟方法printInfo(它是GeoObject中固有的)来打印Marker类对象中存储的信息。问题出在这一行:str << GeoObject::getDesc() << ": " << GeoObject::getPoint().Print() << ", " << size << ", "<< colour ;
我得到error: no matching function to call to 'Point::Print()'
由此我得出结论,GeoObject::getPoint确实返回了一个Point类型的对象,我不明白为什么我不能打印坐标。
以下是代码的重要部分(我省去了与此问题无关的所有代码)
(Marker.cpp)
string Marker::printInfo() const {
ostringstream str ; // used like ostream out
// get the description given to the GeoObject stored in this Marker
str << GeoObject::getDesc() << ": " << GeoObject::getPoint().Print() << ", " << size << ", "<< colour ;
return str.str() ; // take stringversion of string }
(GeoObject.h)
Point getPoint() const
{
return coordinate ;
}
(Point.cpp)
void Print(ostream &out)
{
out << longt <<", "<<lat ;
}
Print
将ostream
作为参数。
void Print(ostream &out)
更改此行:
str << GeoObject::getDesc() << ": " << GeoObject::getPoint().Print() << ", " << size << ", "<< colour ;
对此:
str << GeoObject::getDesc() << ": ";
GeoObject::getPoint().Print(str);
str << ", " << size << ", "<< colour ;
相关文章:
- 使用 <list> (错误 C2760) 打印队列的元素
- 任何人都可以弄清楚这段代码如何显示运行错误?它打印无限时间 -1 以及正确答案
- 为什么重载运算符<<打印特征类成员会导致段错误?
- 我编写了以下代码来读取C++矩阵,然后打印其行和列.我收到此错误
- 我在C++中编写了一个方法来打印树类的预序,但它显示了分割错误
- 错误含义;以二进制形式打印数字
- 通过基类引用派生类后打印的错误值
- 如何在没有打印语句的情况下报告用户输入错误
- 为什么没有打印错误消息
- C++打印模板容器错误(错误:"运算符<<"的不明确重载)理解?
- 错误:变量或字段'PrintEntity'声明无效无效打印实体(实体 e);
- 将矢量的整数内容打印为字符串会导致分割错误
- 为什么我的C++代码在以下打印链表的代码片段中显示分段错误?
- C++ 添加编译器警告,以错误使用自定义打印/日志功能
- 尝试用纯 c 编程 arduino,得到以下错误:预期的"="、""、";",'asm'或"打印"之前的'__attribute__'|
- Python - 从 c++ DLL 错误打印值
- 使用std :: String ptr的错误打印std :: String
- 枚举类的GoogleTest测试错误打印
- 分段错误:打印动态数组时为 11
- Ustring错误(打印期间)