[solved] deal cards and add to the scene
-
error C2248: 'QGraphicsPixmapItem::QGraphicsPixmapItem' : cannot access private member declared in class 'QGraphicsPixmapItem'
error C2248: 'QGraphicsPixmapItem::operator =' : cannot access private member declared in class 'QGraphicsPixmapItem'
And that's compiler's output:
1> c:\qt\5.2.1\msvc2012\include\qtwidgets\qgraphicsitem.h(866) : see declaration of 'QGraphicsPixmapItem::QGraphicsPixmapItem'
1> c:\qt\5.2.1\msvc2012\include\qtwidgets\qgraphicsitem.h(822) : see declaration of 'QGraphicsPixmapItem'
1> This diagnostic occurred in the compiler generated function 'Card::Card(const Card &)'and
'Card &Card::operator =(const Card &)'
-
I can't believe I did it (given my almost non-existent experience), but I finally got rid of the errors by providing my own class copy and assignment operator constructors. Please keep tuned though, will see where it leads me to.. :)
-
What you are doing is risky, you've got the error because the base class (QGraphicsPixmapItem ) explicitly forbids the copy.
If you look at QGraphicsScene you see that you addItem takes a pointer to an item
-
I see what you're saying. I actually may be having problems because of that at the moment (not sure yet though). How would you go about this issue then? Quite frankly, I still don't know which which part of my program causes the error.
-
Just allocate your Cards on the heap and not on the stack
-
I tried that, although I still can't remove copy and assignment operator constructors without getting the same error..
-
Because somewhere in your code you are doing a copy. Are you using a QList<Card> or something similar ?
-
I saw your reply in my other post and I indeed did do copies by using vector. I'm changing my code around now.
Check this line @ vector<Card*> * player = new vector<Card*>; @ Is it correct? And if so, how do I iterate through player? I'm getting a little confused with all these pointers.
-
Just use vector<Card *> player, there's no need of a pointer for the vector
-
@
for (vector<Card*>::iterator iter = player.begin();
iter != player.end(); ++iter)
{
qDebug() << iter->GetSuit()
}
@How do I call GetSuit() function? This is obviously incorrect
-
With
@(*iter)->GetSuit();@
You should be good
-
Tried it before I asked :) But I get an error: "expression must have pointer-to-class type"
-
Sorry, there was a mistake in my code example
-
Ah, simple as that. Works like a charm :)
-
Yes, sometimes it's a simple thing :) But can be hard to track down :-D