Like Tree1Likes
  • 1 Post By Elkvis

Different between Class and Struct

This is a discussion on Different between Class and Struct within the C++ Programming forums, part of the General Programming Boards category; When I see at template, there's word name "Class". and I don't know what different purpose of Class and struct: ...

  1. #1
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    Question Different between Class and Struct

    When I see at template, there's word name "Class". and I don't know what different purpose of Class and struct:
    for example:
    Code:
    class avatar{
    public:
         int City;
         int address;
    }
    struct avatar{
          int City;
          int address;
    }
    I don't know what different purpose of two type of declare, above. Except that, at "class", there some different points I have known like "Method". (but if something you can use by "Method", you also can use it on struct by another way)

    So, who can help me please.
    thanks

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    You need to sit down and learn C++, these aren't quick topics to breeze through. Start with our C++ tutorials and work your way through to the end. I wouldn't necessarily skip over things just because you have been programming in Pascal. Look through the lessons, read quicker through the topics you know already, but still read through.

    As for using the STL (Standard Template Library) you can get by without getting into the exacts of template implementation in C++, however I wouldn't necessarily recommend it.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Quote Originally Posted by hqt
    When I see at template, there's word name "Class".
    You should learn about template programming to understand this. Note that C++ keywords are case sensitive, so it is class, not Class.

    Quote Originally Posted by hqt
    I don't know what different purpose of Class and struct:
    They serve the same purpose, unless distinguished by convention, e.g., the struct keyword might be reserved to define aggregate structs that have no member functions and only public member variables. There are differences with respect to access control, but these should be evident if you were only to follow proper instructional material as AndrewHunter advised.
    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

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,421
    based on your example above, the two are functionally identical.

    the difference is default access level. with a struct, everything is implicitly public unless you specify that it should be private or protected, whereas a class is just the opposite - everything is private unless explicitly made public.

    aside from that fact, there is no difference that I am aware of.
    quzah likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. struct vs class
    By jack_carver in forum C++ Programming
    Replies: 13
    Last Post: 11-30-2009, 11:09 PM
  2. struct or class?
    By George2 in forum C++ Programming
    Replies: 24
    Last Post: 12-05-2007, 10:55 AM
  3. Making a (atom) class in a (struct) class makes big errors!
    By Yarin in forum Windows Programming
    Replies: 4
    Last Post: 09-11-2007, 07:18 PM
  4. Class Or Struct?
    By appleGuy in forum C++ Programming
    Replies: 6
    Last Post: 06-27-2007, 11:06 PM
  5. Using Struct and Class?
    By bob2509 in forum C++ Programming
    Replies: 4
    Last Post: 10-01-2002, 10:49 PM

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