use*_*960 1 c++ eclipse return reference function
试图减去两个向量.最后它应该像:
vector1.sub(vector2);
Run Code Online (Sandbox Code Playgroud)
Custom Variable Vektor定义为:Vektor(double x, double y, double z)
.现在,我要访问的x
,y
,z
坐标通过input.x
等告诉我
Run Code Online (Sandbox Code Playgroud)conversion from 'Vektor*' to non scalar type 'Vektor' requested.
为何坚韧??? 是否无法从值中减去对值的引用?
顺便说一句,我是SO的新手,所以我可以随意为我做错任何事!
Vektor Vektor::sub(const Vektor& input) const
{
Vektor subresult = new Vektor(x - input.x, y - input.y, z - input.z);
return subresult;
}
Run Code Online (Sandbox Code Playgroud)
你不应该new
在这里使用,只是按价值返回
Vektor Vektor::sub(const Vektor& input) const
{
return Vektor(x - input.x, y - input.y, z - input.z);
}
Run Code Online (Sandbox Code Playgroud)
另请注意,您可以覆盖,operator-
以便您可以使用v1 - v2
每种类型的语法执行减法Vektor
.
归档时间: |
|
查看次数: |
45 次 |
最近记录: |