Jump to content
  • Advertisement
Sign in to follow this  
loadsaEmone

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

This topic is 2634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!