Thread: structs in c++

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    36

    structs in c++

    Quick question:
    Someone told me that it's not customary to use structs in c++,
    is this true?

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    C++ structs and classes have no difference except the visibility option....in struct default visibility mode is public whereas in classes its private....

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    so your saying that there is no reason to use structs in c++?

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    There probably isn't much need for you to use structs while writing new programs, but a lot of libraries / API's use them (win32 for example), so you will still use them at some point.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Quote Originally Posted by owi_just
    so your saying that there is no reason to use structs in c++?
    Use whatevr you feel like

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    I tend to use struct out of habit when I know I wont need any member functions.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Technically, there is no reason to use classes instead of structs in C++ code. They are the same thing, apart from default access specifiers.

    structs are used to implement PoD (Plain old Data) types (which, broadly, means a struct type that would be understood by a C compiler: no user supplied constructors, destructors, member functions, private or protected attributes,...). PoD allow data structures to be passed to functions that are written in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  2. Multidimentional structs + memcpy() == FAIL
    By Viper187 in forum C Programming
    Replies: 8
    Last Post: 06-18-2008, 02:46 AM
  3. packed structs
    By moi in forum C Programming
    Replies: 4
    Last Post: 08-20-2002, 01:46 PM
  4. ArrayLists + Inner Structs
    By ginoitalo in forum C# Programming
    Replies: 5
    Last Post: 05-09-2002, 05:09 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM