Thread: "Struct" or "Class"?

  1. #1
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64

    "Struct" or "Class"?

    Hi,
    I have completely learned the languages "C" and "Java".
    In Java there were only Classes but NO Structures. And now
    when I am learning "C++" language, I am a little bit confused:
    Why, when there exist the Classes in C++, should I use Structures?

    Or I will ask in another way: it's good to use ONLY Classes and the
    Structures DON'T use ANYWAY?


    Thanks.

    Petike

  2. #2

    Join Date
    Apr 2008
    Location
    USA
    Posts
    76
    In C++, structures and classes are the exact same thing, except that members in structs are public by default, whereas members in classes are private by default.

    Typically, structs are used for Plain Old Data (similar to a struct in C), but actually a struct can have anything a class can.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    In terms of the languages you listed:

    • If I want to write a Java style class, I would use a C++ class.
    • If I want a C style struct, I would use a C++ struct.


    But you obviously don't have to do it that way.

  4. #4
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64
    Thanks you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting code about "struct" in "union"
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2008, 04:37 AM
  2. "class" problem
    By tinkywinky in forum C++ Programming
    Replies: 5
    Last Post: 11-03-2005, 05:42 AM
  3. "class" errors!
    By SyntaxBubble in forum Game Programming
    Replies: 1
    Last Post: 03-17-2002, 04:21 PM
  4. #Include "class" problems
    By Unregistered in forum C++ Programming
    Replies: 17
    Last Post: 11-26-2001, 10:40 AM