小编Wen*_*nyu的帖子

对于C++ Vector3实用程序类实现,是否比struct和class更快?

出于好奇,我用3种方式实现了vector3实用程序:array(带有typedef),类和结构

这是数组实现:

typedef float newVector3[3];

namespace vec3{
    void add(const newVector3& first, const newVector3& second, newVector3& out_newVector3);
    void subtract(const newVector3& first, const newVector3& second, newVector3& out_newVector3);
    void dot(const newVector3& first, const newVector3& second, float& out_result);
    void cross(const newVector3& first, const newVector3& second, newVector3& out_newVector3);
    }

    // implementations, nothing fancy...really

     void add(const newVector3& first, const newVector3& second, newVector3& out_newVector3)

    {
        out_newVector3[0] = first[0] + second[0];
        out_newVector3[1] = first[1] + second[1];
        out_newVector3[2] = first[2] + second[2];
    }

    void subtract(const newVector3& first, const newVector3& …
Run Code Online (Sandbox Code Playgroud)

c++ optimization performance physics utility

5
推荐指数
1
解决办法
550
查看次数

标签 统计

c++ ×1

optimization ×1

performance ×1

physics ×1

utility ×1