【发布时间】:2016-03-05 12:10:31
【问题描述】:
我有这个代码,并且在行中
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;
}
【问题讨论】:
-
访问什么?请在您的问题中添加完整的错误消息。
-
错误:不允许转换为无法访问的基类“表”。