P
Prasanna
Hi,
I am enountering this problem when compiling my code. error C2678:
binary '==' : no operator defined which takes a left-hand operand of
type 'const class whatever'
I have the template class defined like this:
template<unsigned p> class GF{
public:
...
bool operator==(const GF<p>&);
unsigned& element();
...
private:
....
elm;
....
};
template<unsigned p>
bool GF:perator==(const GF<p>& gfe)
{
if(elm==gfe.element())
return true;
return false;
}
template<unsigned p>
unsigned& GF::element()
{
return &elm; <---- i am returning the reference
}
I have one more class which has a vector<GF<2> > as its data member.
And i do an operation like this:
vector1 == vector2 where both are vector<GF<2> >.
I read the previous posts in this group and the solution for this
problem is said as making the == operator aa const. Like
boool operator == (const GF<p>&) const;
But if i do that, i get the following compiler error. error C2662:
'element' cannot convert 'this' pointer from 'const class GF<2>' to
'class GF<2>&'
May be the problem is because my element() function is returning the
reference. But i want it that way. How do i solve this?
Thanks.
Prasanna.
I am enountering this problem when compiling my code. error C2678:
binary '==' : no operator defined which takes a left-hand operand of
type 'const class whatever'
I have the template class defined like this:
template<unsigned p> class GF{
public:
...
bool operator==(const GF<p>&);
unsigned& element();
...
private:
....
elm;
....
};
template<unsigned p>
bool GF:perator==(const GF<p>& gfe)
{
if(elm==gfe.element())
return true;
return false;
}
template<unsigned p>
unsigned& GF::element()
{
return &elm; <---- i am returning the reference
}
I have one more class which has a vector<GF<2> > as its data member.
And i do an operation like this:
vector1 == vector2 where both are vector<GF<2> >.
I read the previous posts in this group and the solution for this
problem is said as making the == operator aa const. Like
boool operator == (const GF<p>&) const;
But if i do that, i get the following compiler error. error C2662:
'element' cannot convert 'this' pointer from 'const class GF<2>' to
'class GF<2>&'
May be the problem is because my element() function is returning the
reference. But i want it that way. How do i solve this?
Thanks.
Prasanna.