سؤال

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