into my class Class, then how should I initialise that struct upon the construction of Class? A single temporary object is created like this: QIcon(":/images/exit.png")?
uh.. I don't know whether you can have an unnamed struct with a constructor at all. Just make a named struct out of it and assign them in the initializer list of your constructor:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
struct IconsType // IconsType is the name of the struct. You used no name here.
{
QIcon −
QIcon +
QIcon &exit;
IconsType() // constructor.
: minus("/images/minus.png")
, plus("/images/plus.png")
, exit("/images/exit.png")
{}
};
// now you can allocate the global variable "icons" as const, if you want to.
const IconsType icons;
Of course, you should probably move the constructor to a cpp file.
So I can't initialise elements of struct from Class, just from within what you call IconsType?
I don't quite get what you are trying to achieve. If you are sure, that "QIcon&" is correct and you want to have a reference to another QIcon, then this has to be stored somewhere.
If your variable "icons" is a global variable, then this is not really possible, since you can not really guarantee in which order global variables are initialized.
Hm.. QIcon belongs to QT, right? IIRC, QT has some kind of memory management build-in, and you have to allocate the objects using "new QIcon(...)" anyway.
If you really speak about QT, I think I better step back and let someone else explain. I haven't worked with QT for a very long time and when I did once, the memory stuff there always confused me.