문제

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"
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top