Thread: structs vs classes

  1. #1
    Registered User
    Join Date
    Jan 2010

    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
    That's it (including default inheritance type):

    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
    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
    struct A {};
    class B : A {};
    Will A be private or public in B?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    A will be private.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 10:16 AM
  2. classes, structs and unions
    By Luciferek in forum C++ Programming
    Replies: 24
    Last Post: 08-09-2008, 10:26 AM
  3. Why use Classes instead of Structs?
    By yaya in forum C++ Programming
    Replies: 12
    Last Post: 03-16-2008, 12: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