structs vs classes

This is a discussion on structs vs classes within the C++ Programming forums, part of the General Programming Boards category; Is the only difference between a struct and class the default access modifier (public vs private) or is there some ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    412

    structs vs classes

    Is the only difference between a struct and class the default access modifier (public vs private) or is there some other differences that I have missed?

    I have only tested under msvc but they appear to be the same there (besides default access). Is this msvc specific or are they the same under all c++ compilers?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    That's it (including default inheritance type):

    Code:
    class A: B // == class A: private B
    
    struct A: B // = struct A: public B
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    I see. I didn't even think of the inheritance access because I didn't know you were allowed to not explicitly specify it
    Does inheritance access go by the base or the derived object? Ie
    Code:
    struct A {};
    class B : A {};
    Will A be private or public in B?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,101
    A will be private.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs or classes?
    By legit in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2009, 11:16 AM
  2. classes, structs and unions
    By Luciferek in forum C++ Programming
    Replies: 24
    Last Post: 08-09-2008, 11:26 AM
  3. Why use Classes instead of Structs?
    By yaya in forum C++ Programming
    Replies: 12
    Last Post: 03-16-2008, 01:39 AM
  4. Are structs and classes the same thing?
    By dwks in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2005, 03:21 PM
  5. Classes or Structs faster for Lists
    By White Rider in forum C++ Programming
    Replies: 24
    Last Post: 04-05-2002, 03:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21