定义基类A,有数据成员x,函数成员getx()用来返回x的值;派生类B公有继承A类,有数据成员y函数成员gety()用来返回x值;在主函数中定义对象测试该类
#include<iostream>
using namespace std;
class A
{private:
int x;
public:
void c(int xx)
{x=xx;}
int getx(){return x;}
};
class B:public A
{
public:
void d(int x,int yy)
{c(x);y=yy;}
int getY(){return y;}
private:
int y;
}
int main()
{
B b;
b.c(3);
cout<<b.getY()<<endl;
return 0;
}
问题出在哪里了? 有没有大神帮忙编一下我参考 C++新手
#include<iostream>
using namespace std;
class A
{private:
int x;
public:
void c(int xx)
{x=xx;}
int getx(){return x;}
};
class B:public A
{
public:
void d(int x,int yy)
{c(x);y=yy;}
int getY(){return y;}
private:
int y;
}
int main()
{
B b;
b.c(3);
cout<<b.getY()<<endl;
return 0;
}
问题出在哪里了? 有没有大神帮忙编一下我参考 C++新手