gpt4 book ai didi

C++ 构造函数实现错误

转载 作者:行者123 更新时间:2023-11-27 23:20:26 25 4
gpt4 key购买 nike

C++ 构造函数实现错误

我有2个类(class)

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!!!!

关于C++ 构造函数实现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13383442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com