Re: Operator overloading in memberclass.
On 8/21/2011 6:26 PM, Marz wrote:
I'm running ubuntu 11.04 using codeblocks. I'm working on an SDL
based
game. And, I keep getting the following error: error: no match for
?operator=? in ?*(((Animation*)this)->Animation::FrameList + ((unsigned
int)(((unsigned int)index) * 44u))) = frame?
Here's a reduced representation of the code.
//character.h////////////////////////////////////////////////////////
class Frame
{
public:
Frame operator=(const Frame frame);/*<---...tried every
configuration of this line.*/
The idiomatic form is
Frame& operator=(const Frame&);
A much less idiomatic form is
Frame& operator=(Frame&);
There is a move assignment operator, but it's very new and you probably
don't care about it.
};
class Animation
{
public:
void SetFrame(int index, Frame * frame);
private:
Frame *FrameList;
It's an array of Frame objects.
}
//character.cpp //////////////////////////////////////////////////////////////
Frame Frame::operator=(const Frame frame)
{
}
void Animation::{
You probably mean
void Animation::SetFame(int index, Frame * frame) {
FrameList[index]=frame;
Now, think about it. 'frame' is a *pointer* to Frame. You're trying to
assign a POINTER to an object. Ain't gonna work, unless you define the
assignment operator to take a pointer instead of a reference or a value.
}
V
--
I do not respond to top-posted replies, please don't ask