I have this pseudo code. This code may not be 100% correct. My question is when you declare an object using the heap? which is the proper way to access the following data. Meaning if you declare something on the heap should InfoMap also be declared on the heap? I know both would work so does that mean the compiler will figure out the best way to handle this?
class InfoMap
{
InfoMap(){}
QString name;
int age;
}
class InfoData
{
InfoMap RetrieveInfoList()
{
InfoMap map;
map.name = "name1";
map.age = 21;
return map;
}
InfoMap* RetrieveInfoList2()
{
InfoMap *map = new InfoMap();
map->name = "name1";
map->age = 21;
return map;
}
}
In a class that uses InfoData
void SomeClass::RetrieveData1()
{
InfoData *data = new InfoData();
InfoMap *map = data->RetrieveInfoList();
qDebug() << map->name << map->age;
}
void SomeClass::RetrieveData2()
{
InfoData *data = new InfoData();
InfoMap map = data->RetrieveInfoList2();
qDebug << map.name << map.age;
}