0

Possible Duplicate:
What are the differences between struct and class in C++

I am looking at somebody header file for a structure, but it looks like functions are a part of this structure... so then this is a class but how to abstantiate? or use?

struct Recording
{
    FLAG mode;  
    unsigned short intervals;   
      unsigned short saved_cycles;                                      
    virtual void SavetoFile( FILE *file, 
        bool Control, 
        PhaseData *__phaseData = NULL   
        );

    virtual bool LoadfromFile( FILE *file, 
        bool Control, 
        PhaseData *__phaseData = NULL 
        );
};
Community
  • 1
  • 1
jdl
  • 6,151
  • 19
  • 83
  • 132
  • A structure is a class in C++ - just use it like any other class. – Michael Burr Sep 01 '11 at 23:41
  • @jdl: Are you asking if this is a class or struct, or is your question "how to abstantiate? or use?" If the latter, what do you mean/what does that mean? – ssube Sep 01 '11 at 23:46

4 Answers4

3

In C++ class and structare identical, except that the default access specifier for the former is private, while for the latter it is public.

class Base { /* .. */ };

class Foo : Base
{
  int i;
};

struct Bar : Base
{
  int i;
};

In the above code, Foo inherits privately from Base while Bar does so publicly. Similarly, Foo::i is private while Bar::i is public. Note that the visibility of i in both cases has nothing to do with inheritance i.e. it'd be the same even if Foo and Bar did not inherit from Base.

Other than these differences, everything that you can do with one, you can also do with the other.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
0

In C++ the only meaningful difference between a class and a struct is that variables and functions of a class are private by default, and of a struct they are public by default.

Chad
  • 18,706
  • 4
  • 46
  • 63
0

All subobjects (members AND bases) are private by default when using the class keyword, public by default with struct, and both define a class type.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

The features are struct are that:

All members are public by default. Inheritance is public by default, i.e. if a struct inherits from a class or a struct it is public.

With a class both of the above are private by default, i.e. if you oo not specify others.

With regards to data members, this makes it compatible with C (where structs can only have data members) which means you can use your C structs in C++ too.

There are occasions where, even in C++, structs are still used, but my own preference is generally to use the word "class" unless I specifically want all my data members public, which happens on occasion where you are simply grouping them together.

The code posted would probably benefit from private data members, as well as const-correctness and possibly making the virtual methods abstract. Also would need a virtual destructor as it has virtual methods.

In addition you should not be using identifiers beginning with two underscores unless you are implementing "the system".

CashCow
  • 30,981
  • 5
  • 61
  • 92