Classes vs Structs

This is a discussion on Classes vs Structs within the C++ Programming forums, part of the General Programming Boards category; Dear everybody .. I've skimmed the web, searching for actual difference between classes and structures in C++ .. I've found ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    Classes vs Structs

    Dear everybody ..

    I've skimmed the web, searching for actual difference between classes and structures in C++ .. I've found no more than:

    * struct defaults to public, while classe defaults their members to private.

    * Conventionally, structs are used to group data, while classes are used for grouping data and methods to operate on.

    * structs (if don't contain methods) can be compatible with C programs, which class keyword isn't known in C.

    * Conventionally, classes are used for building libraries rather than structs (which can be used as well for libraries)

    and finally, Use a struct if you just need a container of related data; use a class if you need mechanisms for operating on that related data internally.

    Am I missing other difference ..??

    Regards,
    Me


  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    is it true that structs don't allow inheritance ?

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,828
    Quote Originally Posted by afesheir View Post
    Dear everybody ..

    I've skimmed the web, searching for actual difference between classes and structures in C++ .. I've found no more than:

    * struct defaults to public, while classe defaults their members to private.

    * Conventionally, structs are used to group data, while classes are used for grouping data and methods to operate on.

    * structs (if don't contain methods) can be compatible with C programs, which class keyword isn't known in C.

    * Conventionally, classes are used for building libraries rather than structs (which can be used as well for libraries)

    and finally, Use a struct if you just need a container of related data; use a class if you need mechanisms for operating on that related data internally.

    Am I missing other difference ..??

    Regards,
    Me

    No, you have the gist of it.

    Quote Originally Posted by afesheir View Post
    is it true that structs don't allow inheritance ?
    False.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    Thanks Elysia

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. structs vs classes
    By _Mike in forum C++ Programming
    Replies: 3
    Last Post: 02-06-2010, 10:39 AM
  2. Structs or classes?
    By legit in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2009, 10:16 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. Classes and Structs
    By mcorn in forum C++ Programming
    Replies: 1
    Last Post: 12-10-2002, 09:11 AM
  5. Classes or Structs?
    By DeanDemon in forum C++ Programming
    Replies: 12
    Last Post: 12-05-2002, 02:58 AM

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