c++ - 这两段代码谁能看出区别?
PHP中文网
PHP中文网 2017-04-17 13:17:56
0
2
530
glm::vec3 cameraPos = glm::vec3(1, 1, 3);
glm::vec3 cameraFront = glm::vec3(-1.0f, -1.0f, -3.0f);

glm::vec3 center;
center = cameraPos + cameraFront;
view = glm::lookAt(cameraPos, center, cameraUp);
glm::vec3 center = cameraPos + cameraFront;
view = glm::lookAt(cameraPos, center, cameraUp);

这个view是相机视图矩阵,上一段代码能显示出物体,下一段就是显示不出来,

glm::vec3 center;
center = cameraPos + cameraFront;

glm::vec3 center = cameraPos + cameraFront;

对象赋值上面两种方式有何区别?编译器 apple llvm 7.0

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
大家讲道理
glm::vec3 center;                  // 调用默认构造函数(default constructor)创建 center
center = cameraPos + cameraFront;  // 调用 operator= 拷贝赋值运算符

glm::vec3 center = cameraPos + cameraFront;  // 调用拷贝构造函数(copy constructor)创建 center

This problem may occur if the implementation of glm::vec3's copy constructor and copy assignment operator are different. For example, if dynamic memory is used in glm::vec3, you must implement the copy constructor and copy assignment operator yourself. The default is shallow copy.

According to the title description

The previous piece of code can display the object, but the next piece of code cannot display it

I guessglm::vec3This class is likely to use the default copy constructor.

迷茫

I guess an implicit transformation may have occurred

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!