Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: Struct into a C++ class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Struct into a C++ class

    Quote Originally Posted by wysota View Post
    We have shown you two different approaches to the same problem. In tbscope's code MyStruct is just a public structure, in my code it is defined in the scope of the MyClass class, so its full name is MyClass::MyStruct. My code is better encapsulated, his is more reusable.
    Ok thank you.
    Franco Amato

  2. #2
    Join Date
    Feb 2009
    Posts
    20

    Default Re: Struct into a C++ class

    there are of course use cases for a struct in a class.
    When the struct is in the private section you can bundle some internal data.
    And the struct can't be created from outside.

    e.g. when I have to store more then two variables in one vector I use a struct for it, thats better then a boost::tuple, because when you acces the data you can better read your code.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Struct into a C++ class

    You could put a class in the private section of a class and bundle your internal data there too, and it couldn't be created from outside.

    The only real difference betwen struct and class is that a struct is by default public, whereas a class is by default private.

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: Struct into a C++ class

    How can I use the famous typedef?

Similar Threads

  1. QList<struct>
    By Axsis in forum Newbie
    Replies: 11
    Last Post: 12th October 2015, 07:48
  2. struct QbufferPrivate error!!
    By chochatown in forum Qt Programming
    Replies: 0
    Last Post: 27th May 2009, 15:37
  3. QDataStream class/struct & stream operators
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 19:40
  4. Struct in network
    By sribalaji in forum Qt Programming
    Replies: 7
    Last Post: 26th March 2008, 10:38
  5. struct problem...
    By hiuao in forum General Programming
    Replies: 3
    Last Post: 5th April 2007, 07:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.