我有这个代码,并在行 tp = new asp_table
,它不会让我编译说我没有访问权限。 我不明白为什么?我试图做一个从基类到派生类的指针,但它不会让我。我想明白为什么。多态性和受保护的继承问题
class table {
int size;
int priority;
public:
table(int s=0,int p=0):size(s),priority(p){ }
virtual void print(){}
};
class stud_table:public table {
char * name;
int gr;
public:
void print() {cout<<"students table"<<endl;}
~stud_table() {delete []name;}
};
class asp_table:protected table {
char* thesis;
};
int main() {
stud_table st;
table * tp = &st;
tp = new asp_table;
stud_table * stp = &st;
cout<<"Program"<<endl;
return 0;
}
访问什么?请将完整的错误消息添加到您的问题。 – emlai
错误:不允许转换为不可访问的基类“表”。 – Timur