-3

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

The keyword class and struct are almost equivalent in c++, only difference between a structure and a class is that structure members have public access by default and class members have private access by default.

Is there any advantage (memory usage, speed, optimization etc) in using keyword struct instead of class when all member variables of a class are required to have public access.

Edit:

I appreciate everyone and SRN for pointing the other link I was asking if any know any memory usage, speed difference. Please read the question carefully before giving negative points.

Community
  • 1
  • 1
katta
  • 245
  • 1
  • 4
  • 11
  • 1
    http://stackoverflow.com/questions/92859/what-are-the-differences-between-struct-and-class-in-c – SRN Aug 17 '12 at 14:09
  • 2
    Your question doesn't make sense. You're asking "I know the only difference is [x], so are there any other differences?" –  Aug 17 '12 at 14:11
  • 1
    see also http://stackoverflow.com/questions/92859/what-are-the-differences-between-struct-and-class-in-c – fduff Aug 17 '12 at 14:12
  • 1
    inheritance is public dy default for structs and private for classes – Andrew Aug 17 '12 at 14:14
  • 1
    @Katta - Originally, the language that became C++ had classes with member functions and access specifiers added to what was already in C. Only later did these rules "spill over" to structs as well. It's just a historical "accident" that we ended up with two almost identical features. Perhaps someone asked "Why can we not have member functions in a struct?". "No particular reason". – Bo Persson Aug 17 '12 at 14:49

2 Answers2

0

No. You named it: The only difference is the default access level.

Observe for example that you can forward-declare a struct which is later declared as a class, and vice versa:

struct FooObject;

...

class FooObject { int x; }; // OK
Stefan Majewsky
  • 5,427
  • 2
  • 28
  • 51
  • 2
    You can also use `class` instead of `typename` for templates, but you can't use `struct` there. – David Aug 17 '12 at 14:22
0

No, it's preferred by some only due to semantic purposes.

doomrobo
  • 88
  • 6