Is this the right way in C++?

LumbergTech

Diamond Member
Sep 15, 2005
3,622
1
0
In java I would have done:

Code:
fillArray(myArray);

void fillArray(objArray myArray)
{
     for(int x = 0 ; x < 5; x++)
          myArray[x] = new Parameter("Description", "Name", "Value");
}

Can I do the same thing in C++?

Code:
QList<Parameter> parameters;

fillList(parameters);

void fillList(QList<Parameter>& myList)
{
     for(int x = 0; x < 5; x++)
          myList.append(new Parameter("Description", "Name", "Value");
}

IF this is not the correct way to handle things, what can I do differently?
 
Last edited:

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
using new in C++ returns the pointer to the object or data structure or w/e. you would have to declare the list as QList<Parameter *> if you want to use new. that or don't use new.