overloading *, +, -'operators for vector class

前端 未结 4 1383
说谎
说谎 2021-01-06 08:33

I\'m writing a Line class to make numerical methods and I want these operators (*, +, -) to make my code more readable and easier to understand.



        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-06 09:21

    You have to overload the operators at global scope:

    vector operator*(const vector& v, double alfa)
    {
        ...
    }
    
    vector operator+(const vector& v1, const vector& v2)
    {
        ...
    }
    
    vector operator-(const vector& v1, const vector& v2)
    {
        ...
    }
    

    As for the linker errors, it just looks like you didn't implement the Line constructor and destructor.

提交回复
热议问题