Domanda

I am trying to define the unary operator - on an array of char

Int operator - (const char *rs){
  Int b(rs);
  return  b;
}

but I am getting two error messages

IntelliSense: nonmember operator requires a parameter with class or enum type

error C2803: 'operator -' must have at least one formal parameter of class type

I looked up the error code on msdn but I still can't see what I am doing wrong.

I want to perform an operation like

-"1256ght78"
È stato utile?

Soluzione

You cannot. One of parameters should have class-type for which you overload. You cannot overload operators for standard types.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top