Differences in C++ between struct and class

J

Javier

Hi,
I have just read that struct's in C++ can have public and private
members, so I have one question:
Which are the differences between classes and structs (besides
constructors and destructors?).
Thanks.
 
I

Ian Collins

Javier said:
Hi,
I have just read that struct's in C++ can have public and private
members, so I have one question:
Which are the differences between classes and structs (besides
constructors and destructors?).
Thanks.
There is no difference with regard to constructors and destructors. The
only difference is the default access and inheritance is public for a
struct and private for a class.
 
G

Gavin Deane

Hi,
I have just read that struct's in C++ can have public and private
members, so I have one question:
Which are the differences between classes and structs

Almost nothing.
(besides constructors and destructors?).

That's not a difference. structs have constructors and destructors,
either compiler generated or written by you, in exactly the way
classes do.

Your answer is in the FAQ.
http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.8
The differences described in the first sentence of that FAQ are the
*only* technical differences between a struct and a class. But do note
the rest of the FAQ that describes the different ways the two are
generally used.

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top