overloading *, +, -'operators for vector class

前端 未结 4 1353
说谎
说谎 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条回答
  •  -上瘾入骨i
    2021-01-06 09:11

    Surely the correct thing is to have a Vector object INSIDE line, and not "inherit" from Vector? Generally inheriting from std:: containers is not a great data... I'm pretty sure a "Line" is not actually a vector, it's a "has a" vector. [The rule for "when you inherit" is "X is a Y", where you make a composite object when "X has a Y" - so there is a Y inside X.]

    You will need to declare your constructor and destructor to get rid of your linking error.

    I would also use const Line& as your input to the math operations, as you neve alter the input.

提交回复
热议问题