C++构造函数实现错误



C++ 构造函数实现错误

我有2节课

Map2D(parent) & Map3D(child)

所以这就是发生的事情...

class Map3D : public Map2D
{
private:
int z;
public:
Map3D();
Map3D(int,int,int);
int getZ();
}

下面是我的Map2D

class Map2D
{
friend ifstream& operator>>(ifstream&, Map2D&);
protected:
int x;
int y;
public:
Map2D();
Map2D(int,int);
};
Map2D::Map2D()
{
x=0;
y=0;
}
Map2D::Map2D(int xIn,int yIn)
{
x = xIn;
y = yIn;
}

现在的问题是我尝试实现Map3D,但遇到了问题。 我尝试的内容如下

回到Map3D.cpp

Map3D::Map3D()
{
x=0;
y=0;
z=0;
}
Map3D::Map3D(int xIn,int yIn,int zIn)
{
x=xIn;
y=yIn;
z=zIn;
}
map3d.cpp:18:1: error: extra qualification ‘map3D::’ on member ‘map3D’ [-fpermissive]
map3d.cpp:18:1: error: ‘map3D::map3D()’ cannot be overloaded
map3d.cpp:14:1: error: with ‘map3D::map3D()’
map3d.cpp:25:1: error: extra qualification ‘map3D::’ on member ‘map3D’ [-fpermissive]
map3d.cpp:25:1: error: ‘map3D::map3D(int, int, int)’ cannot be overloaded
map3d.cpp:15:1: error: with ‘map3D::map3D(int, int, int)’

我应该更改什么以使我的实现正确。感谢所有的帮助。

看起来像Map3D声明末尾缺少一个分号

class Map3D : public Map2D
{
private:
int z;
public:
Map3D();
Map3D(int,int,int);
int getZ();
}; // SEMI-COLON HERE!!!!

最新更新