In my header file, I have the following:
private:
ImagePixmapItem *item;
In a function, I create a new ImagePixmapItem like so:
ImagePixmapItem *item(static_cast<ImagePixmapItem *>(scene.addPixmap(p)));
However, this creates a local copy of item.
but if I do this:
*item(static_cast<ImagePixmapItem *>(scene.addPixmap(p)));
I get the following error:
error: ‘((ViewerMain*)this)->ViewerMain::item’ cannot be used as a function
So what is the correct way to make this call?
An initialization like
is only allowed within the declaration of your variable (this is in fact your first example with a local variable), or (for member fields) in the constructor initialization list:
Inside a member function, just assign to it:
(Since it is private, it is not accessible from a nonmember function, except if it is friend of the class.)