The differentiate between structure and class
1. Members of a class are private by defaults and members of a structure are public by defaults . Examplesclass SabbirIf you run this program computer shows error because here s is private .
{
int s;
};
int main( )
{
Sabbir t;
t.s=40;
getchar( );
return 0;
}
struct SabbirIf you run this program compiler work properly because here s is public .
{
int s;
};
int main( )
{
Sabbir t;
t.s=40;
getchar( );
return 0;
}
2. When deriving a struct from a class/struct,default access-specifier for a base class/struct is public.And when deriving a class , default specifier is private .
Example
class Sabbir
{
int s;
};
class derived : Sabbir { };
int main( )
{
Derived d;
d.s=40;
getchar( );
return 0;
}
Here the coding is not working beacuse compiler shows error inheritance is private .
class Sabbir
{
int s;
};
struct derived : Sabbir { };
int main( )
{
Derived d;
d.s=40;
getchar( );
return 0;
}
Here the coding is working beacuse compiler shows that inheritance is public.
0 comments:
একটি মন্তব্য পোস্ট করুন