Operator Overloading in struct

后端 未结 4 1686
無奈伤痛
無奈伤痛 2021-02-07 11:39

Suppose I define this structure:

struct Point {
   double x, y;
};

How can I overload the + operator so that, declared,

         


        
4条回答
  •  轮回少年
    2021-02-07 11:54

    In C++ there's only one difference between a struct and a class: in a struct the default visibility is public while in a class it is private.

    Other than that you can do anything you would do in a class in a struct and it will look exactly the same.

    Write operator overloading in a struct as you would in a class.

提交回复
热议问题