同一基类的不同派生类对象之间不能赋值? 30
#include<iostream>usingnamespacestd;classstudent{public:student(intx=1){a=x;}private:...
#include<iostream>
using namespace std;
class student
{
public:
student(int x=1)
{
a=x;
}
private:
int a;
};
class student1:public student
{
public:
student1(int x)
{
b=x;
}
private:
int b;
};
class student2:public student
{
public:
student2(int x)
{
c=x;
}
private:
int c;
};
int main()
{
student num(0);
student1 num1(1);
student2 num2(2);
num=num2;
//num1=num2; 此句不能通过编译
return 0;
}
为什么倒数第二句不能通过编译,而倒数第三句却可以呢?请详解 展开
using namespace std;
class student
{
public:
student(int x=1)
{
a=x;
}
private:
int a;
};
class student1:public student
{
public:
student1(int x)
{
b=x;
}
private:
int b;
};
class student2:public student
{
public:
student2(int x)
{
c=x;
}
private:
int c;
};
int main()
{
student num(0);
student1 num1(1);
student2 num2(2);
num=num2;
//num1=num2; 此句不能通过编译
return 0;
}
为什么倒数第二句不能通过编译,而倒数第三句却可以呢?请详解 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询