是不是都是针对同一个数据成员m_x和 m_y初始化?如果初始化重复,是不是可以CPoint(x,y)?

#include<iostream.h>
class CPoint
{
public:
CPoint();//默认构造函数
CPoint(int x,int y);
void disp();
void getXY(int &x, int &y);
private:
int m_x;
int m_y;
};
CPoint::CPoint()
{
m_x=0;
m_y=0;
cout<<"调用了CPoint默认构造函数"<<endl;
}
CPoint::CPoint(int x,int y)
{
m_x=x;
m_y=y;
cout<<"调用了CPoint带参数的构造函数"<<endl;
}
void CPoint::disp()
{
cout<<m_x<<","<<m_y<<endl;
}
void CPoint::getXY(int &x,int &y)
{
x=m_x;y=m_y;
}
class C3DPoint:public CPoint
{
public:
C3DPoint();
C3DPoint(int x,int y,int z);
void disp();
private:
CPoint p;
int m_z;
};
C3DPoint::C3DPoint():CPoint()
{
m_z=0;
cout<<"调用了C3DPoint默认的构造函数"<<endl;
}
C3DPoint::C3DPoint(int x,int y,int z):CPoint (x,y),p(x,y) //问题所在行。
{
m_z=z;
cout<<"调用了C3DPoint默认参数的构造函数"<<endl;
}
void C3DPoint::disp()
{
int x=0,y=0;
p.getXY(x,y);
cout<<x<<","<<y<<","<<m_z<<endl;
}
void main()
{
C3DPoint p1,p2(50,80,10);//定义子类的对象P1 P2

p1.disp();
p2.disp();
}
在上面指出问题的一行中,CPoint(x,y)和p(x,y)是否初始化同一片内存区?

在C3DPoint p1 里有以下变量:
p1.m_x // 从CPoint里继承
p1.m_y // 从CPoint里继承
p1.m_z
p1.p.m_x
p1.p.m_y
CPoint(x,y)和p(x,y) 不是重复赋值。
是不同的内存区。
继承就是父类的东西可以用。
所以 p 可以不要。
class C3DPoint:public CPoint 里删除
CPoint p;
问题行改为:
C3DPoint::C3DPoint(int x,int y,int z):CPoint (x,y)
就可以了。
void C3DPoint::disp()
{
int x=0,y=0;
getXY(x,y);
cout<<x<<","<<y<<","<<m_z<<endl;
}
getXY是父类的public 函数,可以直接用