user1372984
user1372984

Reputation:

Unary operator on char[]

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"

Upvotes: 0

Views: 295

Answers (1)

ForEveR
ForEveR

Reputation: 55897

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

Upvotes: 3

Related Questions