Jump to content

C plus plus struct

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by ScoPi (talk | contribs) at 00:16, 15 July 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A C++ struct is actually an extension of the C language struct in that the ability to specify methods is added. In fact, the only difference between a struct and a class in C++ is that by default the former's members are private, whereas in a struct, by default the members are public. An example of a declaration for a C++ struct is:

   struct SomeStruct
   {
       SomeStruct();
       virtual ~SomeStruct();
       void someMethod();
   };

SomeStruct() and ~SomeStruct() are the constructor and destructor, respectively, and someMethod() is a method of the struct. All members are public since no visibility is specified.