我想重载"="运算符以将值从对象赋值给非类int变量

Idr*_*yne -1 c++ overloading assignment-operator

int i;
Integer a; //a class object

i=a; //here a's member variable value should be assigned to 'i'
Run Code Online (Sandbox Code Playgroud)

Rei*_*ica 5

您可以通过从类中提供转换运算符来执行此操作int:

class Integer
{
 // ... stuff
public:
  operator int() const
  { return member_to_assign; }
};
Run Code Online (Sandbox Code Playgroud)