使用 C++ 类,您可以让派生类从其父类继承变量。如何定义派生类以便var2
不继承derivclass
?
class mainclass{
public:
int var1;
char var2;
void test(){
cout<<var1<<var2<<endl;
}
}
class derivclass : mainclass{
public:
void test(){
cout<<var1<<var2<<endl;
//want a compiler error here that var2 is not defined
}
}