0

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)’

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

4

1 回答 1

4

Map3D声明末尾好像缺少分号

class Map3D : public Map2D
{
private:
int z;

public:
Map3D();
Map3D(int,int,int);
int getZ();

}; // SEMI-COLON HERE!!!!
于 2012-11-14T16:59:16.903 回答