用于打印的返回点,已使用错误

Return Point for printing, inherritance used

本文关键字:错误 打印 返回 用于      更新时间:2023-10-16
  • 这个原始问题得到了解决,在评论中是后来出现的问题;

    我如何使用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 ;
}

Printostream作为参数。

void Print(ostream &out)

更改此行:

str << GeoObject::getDesc() << ": " << GeoObject::getPoint().Print() << ", " << size << ", "<< colour ;

对此:

str << GeoObject::getDesc() << ": ";
GeoObject::getPoint().Print(str);
str << ", " << size << ", "<< colour ;