Is it not possible to call C++ operators manually?

后端 未结 6 576
执念已碎
执念已碎 2020-12-31 04:13

I\'m trying to understand operators in C++ more carefully.

I know that operators in C++ are basically just functions. What I don\'t get is, what does the function lo

6条回答
  •  一生所求
    2020-12-31 04:57

    For basic types like int, float, double; the operators are already overloaded/pre-defined, so nothing special can be done for that. And,

    int z = x + y;
    

    is the only way to express/call it.

    For interpretation purpose, actually both the statements,

    int z = operator+(x,y);
    int z = x.operator+(y);
    

    are true (had it been overloadable).

提交回复
热议问题