我正在为我的 C++ 类编写一些代码,但我被困住了。
我实际上正在使用多态动态绑定,我已经成功地将对象存储到我的向量中,现在我想显示存储在向量 ShapeTwoD 中的所有对象。
这是我正在处理的任务的一部分:
Shape2DLin.cpp
void Shape2DLink::Display()
{
vector<ShapeTwoD*>::iterator vectorIt = shapeobject.begin();
while(vectorIt != shapeobject.end())
{
*vectorIt->view();
vectorIt++;
}
}
SquareImp.cpp
void Square::view() const
{
cout << "Area is: " << area << endl;
}
ShapeTwoDImp.cpp
void Square::view() const
{
cout << "Area is: " << area << endl;
}
每当我编译应用程序时,我都会收到以下错误。只是想知道为什么会这样?
D:\School\CSCI204-C++\Assignment\Assign 2\Assign2>g++ -o test Shape2Dmain.cpp Sh
ape2DLink.cpp ShapeTwoDImp.cpp SquareImp.cpp RectangleImp.cpp CrossImp.cpp
Shape2DLink.cpp: In member function 'void Shape2DLink::Display()':
Shape2DLink.cpp:94:14: error: request for member 'view' in '* vectorIt.__gnu_cxx
::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = ShapeTw
oD**, _Container = std::vector<ShapeTwoD*>, __gnu_cxx::__normal_iterator<_Iterat
or, _Container>::pointer = ShapeTwoD**]()', which is of non-class type 'ShapeTwo
D*'