C++ ERROR "no match for operator> in .."

Started by
5 comments, last by Napivo 12 years, 6 months ago
I have a class called Animation with a struct called Frame defined within it.

Header:
#ifndef ANIMATION_H
#define ANIMATION_H

struct Frame
{
int row;
int column;
Frame(int r, int c): row(r), column(c){}
Frame();

};



class Animation
{
public:
Animation();
Animation(int sr, int sc, int mxr, int mxc)
:frame(sr,sc),MAX(mxr,mxc),MIN(sr,sc){}

virtual ~Animation();
void nextFr();
int getRow();
int getCol();
bool operator> (const Frame& param);
protected:

private:

Frame frame;
Frame MAX;
Frame MIN;
};

#endif // ANIMATION_H



cpp:
int Animation::getRow()
{
return frame.row;
}

int Animation::getCol()
{
return frame.column;
}

void Animation::nextFr()
{
frame.column++;
if(frame.column > 9)
{
frame.column = 0;
frame.row++;
}
if(frame > MAX)
{
frame = MIN;
}
}


bool Animation::operator>(const Frame& param)
{
if(frame.row > param.row)
return true;
if(frame.row == param.row)
{
if(frame.column > param.column)
return true;
}
return false;
}


Everytime I try to compile, it gives me an error saying "cpp|32|error: no match for 'operator>' in '((Animation*)this)->Animation::frame > ((Animation*)this)->Animation::MAX'|". Now, what I think this error means is that it thinks that there is no operator ">" defined for the line "frame>MAX"(line 32). This is puzzling to me because I have both defined such an operator in the header and the cpp file right beneath function calling the line in question. Maybe there is something wrong with the way I have declared the operator overload?

Any help is appreciated. Thank you.
Advertisement
Your operator> overload compares Animation and Frame objects, not Frame and Frame objects. If you want to compare Frame objects with each other make it a member of the Frame class, or a non-member operator overload that accepts two Frame object references.
Put the operator in the Frame class. After all, you're comparing a Frame with a Frame. But the way you have defined it, its expecting you to compare an Animation with a Frame.

Edit: SiCrane... You always ninja me!
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Moderator. Flying. First Strike.
Thanks guys, that did it.

Moderator. Flying. First Strike.

Hey, where's Fruny these days?
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Moderator. Flying. First Strike.


Your cards are so funny especially this one:)

http://members.gamedev.net/fruny/forums/magic/working_search.jpg

Sorry completely off topic

This topic is closed to new replies.

Advertisement