我有一个简单的程序来测试我的两个3D矢量的交叉产品是否有效.
#include <iostream>
#include "math\Vec3.h"
using namespace std;
int main(int argc, char **argv)
{
Vec3 v1(1, 23, 5);
Vec3 v2(7, 3, 4);
cout << "Crossing v1 and v2" << endl;
Vec3 v3 = v1.cross(v2);
cout << "crossed" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么在创建变量之后调用析构函数?
这是打印出来的:
Created: Vec3[1, 23, 5]
Destroy: Vec3[1, 23, 5] // Why is the vector destroyed here?
Created: Vec3[7, 3, 4]
Destroy: Vec3[7, 3, 4] // And here?
Crossing v1 and v2
Created: Vec3[77, 31, -158]
Destroy: Vec3[77, …Run Code Online (Sandbox Code Playgroud)