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:
class atom
{
public:
};
class data
{
//int size;
public:
QString name;
//string for standard name from CIF // QList < QList <QList<float> > >xyz; //3d array for XYZ values from CIF
// data(int);
int size;
double aSide;
double bSide;
double cSide;
double alpha;
double beta;
double gamma;
double volume;
atom atom1;
atom atom2;
};
class atom
{
public:
QString type;
};
class data
{
//int size;
public:
QString name; //string for standard name from CIF
// QList < QList <QList<float> > >xyz; //3d array for XYZ values from CIF
// data(int);
int size;
double aSide;
double bSide;
double cSide;
double alpha;
double beta;
double gamma;
double volume;
atom atom1;
atom atom2;
};
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
Bookmarks