对C++下struct 和 类默认继承的认识

 #include <iostream>
using namespace std;
struct struct1{
int data1 ;
double data2 ;
struct1(){
(*this).data1 = data1 ;
(*this).data2 = data2 ;
cout<<"this is output by struct1 function !";
}
public :
void privateFunc(){
cout<<"this is private function , so this massage should never show in console ! \n";
}
};
struct struct2 : struct1{
/* according the result in console , we can get the conclusion : the default inherit method of struct is public */
};
class class1 : public struct1 {
/* if ignore 'public' identifiers , compile will show that privateFunc() in 35 line can't access, this indicate that it is private inhert when subclass is a struct. */
string name ;
public :
class1(){
name = "i'm a class !";
cout<<"this is output by class1 !";
}
};
class class2{
public :
void showClass2(){
cout<<"this is output by class2 ! \n ";
}
};
class class3 : class2{
/* according to the result : showClass2 can't accessiable can prove class default inherit method is private */
};
struct struct4 : class2{
/* default inherit is public */
};
class class4 : struct1 {
/* default inherit is private
*/
}
int main(){
//struct2 onestruct2 ;
//onestruct2.privateFunc();
/* test class default inherit */
//class3 * oneclass3 = class3;
//oneclass3->showClass2();
/* test struct inherit class */
//struct4 onestruct4 ;
//onestruct4.showClass2();
class4 * oneclass4;
oneclass4->privateFunc();
return ;
}
上一篇:PHP用ajia代码写三级联动下拉


下一篇:selenium 怎么处理display:none