Results 1 to 9 of 9

Thread: construction of classes within classes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default construction of classes within classes

    Hi, Im not sure if this is the right place to post this but im new to QT and C++ and i have a question regarding classes and their creation so i thought id try here!

    So want to create a class containg values and then i want to create antoher class inside with more values for organisation. (in matlab which i have used before I would create a structure within a structure). I have this code:

    Qt Code:
    1. class atom
    2. {
    3. public:
    4. QString type;
    5. };
    6.  
    7.  
    8. class data
    9. {
    10. //int size;
    11. public:
    12. QString name; //string for standard name from CIF
    13. // QList < QList <QList<float> > >xyz; //3d array for XYZ values from CIF
    14. // data(int);
    15. int size;
    16. double aSide;
    17. double bSide;
    18. double cSide;
    19. double alpha;
    20. double beta;
    21. double gamma;
    22. double volume;
    23.  
    24. atom atom1;
    25. atom atom2;
    26.  
    27. };
    To copy to clipboard, switch view to plain text mode 
    So now i get a class containing aSide, bSide etc and then two classes for two atoms each containing type. Ok however as the number of atoms can change each time the class data is instanced i need to dynamically assign the number of atom classes on creation.

    e.g.

    data data1(3) - where 3 is the number of atoms i need and would automatically create the instance data1 with 3 atom classes (i.e. atom1 atom2 and atom3...)

    then data data2(5) would create 5 atom classes etc......

    Can anyone explain how to do this please? oes it require the use of a constructor?

    Thanks in advance,

    Matt
    Last edited by high_flyer; 9th January 2011 at 16:35. Reason: code tags

Similar Threads

  1. QT WMI Classes
    By justatiq in forum Qt Programming
    Replies: 31
    Last Post: 10th April 2011, 15:44
  2. Using WMI CLasses
    By newb in forum Newbie
    Replies: 1
    Last Post: 4th June 2010, 19:19
  3. Relationship b/w different classes
    By salmanmanekia in forum Newbie
    Replies: 0
    Last Post: 2nd June 2010, 18:24
  4. fax classes in qt
    By dyams in forum Qt Programming
    Replies: 5
    Last Post: 7th September 2007, 09:14

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.