C++ ambiguous operator for template overload -


i have problem operator overloading:
want write class operator this:

class bignum {     public:         template<class t>         bool operator==(const t &input);         template<class t>         friend bool operator==(const t &a,bignum & b); }; 

it's fine call:

bignum a; int a; a==a; a==a; 

but when calling:

bignum a,b; a==b; 

it compiler error:

[error] ambiguous overload 'operator==' (operand types 'bignum' , 'bignum')
[note] bool bignum::operator==(const t&) [with t = bignum]
[note] bool operator==(const t&, bignum&) [with t = bignum]

and there same problem if change

template<class t> bool operator==(const t &input); 

to

bool operator==(const bignum &input); 

but ok if operator overloads this(but can't doany type==bignum):

class bignum {     public:         bool operator==(const bignum &input);         template<class t>         bool operator==(const t &input); }; 

if want write operator overload can of these:

  • any type == bignum
  • bignum == type
  • bignum == bignum

how should fix it?thank you.

i suggest removing member == template , provide 3 non-member overloads operator== - 2 templated, 1 bignum on left side, on right side; , 1 non-templated bignum on both sides.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -