Sign in to follow this  
loadsaEmone

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

Recommended Posts

I have a class called Animation with a struct called Frame defined within it.

Header:
[code]#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
[/code]


cpp:
[code]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;
}
[/code]

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1317571583' post='4868291']
[url="http://members.gamedev.net/fruny/forums/magic/SiCrane.jpg"]Moderator. Flying. First Strike.[/url]
[/quote]
Hey, where's Fruny these days?

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1317571583' post='4868291']
[url="http://members.gamedev.net/fruny/forums/magic/SiCrane.jpg"]Moderator. Flying. First Strike.[/url]
[/quote]

Your cards are so funny especially this one:)

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

Sorry completely off topic

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this