2016-11-16 91 views
0

所以我试图编写一个简单的摄像头来使用用户输入来移动游戏世界,当我遇到一些非常奇怪的运算符匹配错误(C2677 & C2678)。 他们是从线运算符匹配错误VS2015

camPosition += moveLeftRight * camRight; 
    camPosition += moveBackForward * camForward; 
    camTarget = camPosition + camTarget; 

定义:

float moveLeftRight = 0.0f; 
    float moveBackForward = 0.0f; 

    DirectX::XMVECTOR camPosition; 
    DirectX::XMVECTOR camTarget; 

    DirectX::XMVECTOR camForward = DirectX::XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f); 
    DirectX::XMVECTOR camRight = DirectX::XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f); 

而且错误阅读:

Error C2677 binary '*': no global operator found which takes type 'DirectX::XMVECTOR' (or there is no acceptable conversion) 
    //Hovering "operand types are: float * DirectX::XMVECTOR" 

    Error C2678 binary '+': no operator found which takes a left-hand operand of type 'DirectX::XMVECTOR' (or there is no acceptable conversion) 
    //Hovering "operand types are: DirectX::XMVECTOR * DirectX::XMVECTOR" 

它之前编译。当我使用命名空间DirectX时,它编译得非常好。当我添加一些移动代码时,我想可能会有些事情搞砸了。我删除了命名空间并将DirectX ::添加到了每个定义和函数中。错误。 C2677和C2678的MSDN页面根本没有任何帮助。 Google只给了我简单的东西。

Gyazo链接:

https://gyazo.com/e2f62026d00e8fa82142b24de3fe32b5 https://gyazo.com/f1bbc321abc3a167d519bf1d671edcc6

编辑:我不知道为什么或者怎么样,但是现在的工作。所以,耶...我有一个小时的时间。 >。该死的编码...大声笑。

回答

0

您想使用该运营商:

XMVECTOR XM_CALLCONV  operator+ (FXMVECTOR V1, FXMVECTOR V2); 

我想你已经在某种程度上隐藏着这样的:

namespace 
{ 
    class Scalar { 
    public: 
     Scalar() {} 
    }; 

    inline Scalar operator+ (Scalar s1, Scalar s2) { return Scalar(); } 

    int f() { 
     XMVECTOR a; 
     a = a + a; // Here, you can't access XMVECTOR's operator, 
        // because name lookup stops with first operator found 
    } 
}