-2

I'm looking at some legacy code that looks like it was converted over from C to C++ and there are various classes that have public member variables and nothing else:

class sampleClass
  public:
    int fd;
    customType clientHandle;
    customType serverHandle;
};

From my understanding struct = class with no functions and public members so is this virtually exactly the same as a struct for practical reasons?

What happens when the code is compiled. Is it compiled down to the exact same "stuff" or do they get compiled differently

Jeef
  • 26,861
  • 21
  • 78
  • 156
  • 1
    Lack of research on the site strikes back. The most upvoted dupe [was to be found](http://stackoverflow.com/search?q=%5Bc%2B%2B%5Dstruct+class+difference) in about 20 seconds. – πάντα ῥεῖ Dec 23 '14 at 17:06
  • I specifically asked about the compiler point of view. The other question relate to design point of view. Its is a different question. I want to know how the class and struct is decomposed during compilation. – Jeef Dec 23 '14 at 20:34
  • Ask the compiler's authors then ... – πάντα ῥεῖ Dec 23 '14 at 20:35

3 Answers3

2

It is entirely the same, yes. The only two ways in which structs and classes differ are the default protection of members, and the default inheritance type of base classes.

Sneftel
  • 40,271
  • 12
  • 71
  • 104
0

In C++ only the default accessing differs between struct (public) and class (private).

Gabriel
  • 3,564
  • 1
  • 27
  • 49
0

Difference in struct and class and that is by default members of struct are public, while by default members of class are private.

Even while inheriting from struct, default specifier is public, while for class its private.

You can see my video tutorial on this.

Pranit Kothari
  • 9,721
  • 10
  • 61
  • 137