can struct be inherited in C++ ?
+20
A:
Yes, struct
is exactly like class
except the default accessibility is public
for struct
(while it's private
for class
).
Alex Martelli
2009-06-11 03:44:17
+4
A:
of course. In c++, structs and classes are nearly identical (things like defaulting to public instead of private are among the small differences).
Evan Teran
2009-06-11 03:44:21
Thanks alot ..........
2009-06-11 03:45:16
So, why not accept one of these as your answer?
GMan
2009-06-11 03:46:33
+4
A:
Yes. The inheritance is public by default.
Syntax (example):
struct A { };
struct B : A { };
struct C : B { };
Suvesh Pratapa
2009-06-11 03:45:52
+3
A:
Other than what Alex and Evan have already stated, I would like to add that a C++ struct is not like a C strut.
In C++ a strut can have methods, inheritance ...etc just like a C++ class.
Chad Gorshing
2009-06-11 03:49:29
a C++ struct can be like a C struct. When it is, its called a POD - Plain Old Datatype. It is an important distinction, since for example, only POD structs can be part of unions.
camh
2009-06-11 07:00:29
But PODs can have methods, so are not "like" C structs in the sense which cgorshing is talking about.
Steve Jessop
2009-06-11 11:09:01