Struct and class

This is a discussion on Struct and class within the C++ Programming forums, part of the General Programming Boards category; Is it conventional to use both structs and classes in c++?i recall abachler saying he used struct for objects without ...

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438

    Struct and class

    Is it conventional to use both structs and classes in c++?i recall abachler saying he used struct for objects without member functions,i like this idea as providing clarity while working, to distinguish a complex data type from an object that 'does' things but is this valid c++?
    Last edited by rogster001; 01-25-2010 at 03:17 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,893
    Yes, it is often a convention to use both, but for slightly different purposes. As for valid C++: duh. You can write object oriented C++ and have fun with class templates without ever using the class keyword.
    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

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    I think it is but some disagree with me. My personal policy is this:

    1. A struct cannot have methods, but may have a constructor in order to initialize data. A struct should not encapsulate any functionality.
    2. A class must encapsulate some type of functionality. If a class merely wraps access to variables - IE: is only composed of accessors and mutators - then it should most likely be a struct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. returning class and struct members
    By simone.marras in forum C++ Programming
    Replies: 17
    Last Post: 03-16-2009, 11:10 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

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