So I am trying to work on programming a simple camera to use user input to move around the game world, when I came across some really weird operator matching errors (C2677 & C2678). They are from the lines
camPosition += moveLeftRight * camRight;
camPosition += moveBackForward * camForward;
camTarget = camPosition + camTarget;
Definitions:
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);
And the errors read:
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"
It has compiled before. It compiled perfectly fine when I was using the namespace DirectX. I thought maybe something got messed up when I added some movement code. I removed the namespace and added DirectX:: to every definition and function. Error. The MSDN page for C2677 and C2678 did not help at all. Googlings only gave me with simple stuff.
Gyazo links:
https://gyazo.com/e2f62026d00e8fa82142b24de3fe32b5 https://gyazo.com/f1bbc321abc3a167d519bf1d671edcc6
Edit: I have no idea why or how, but it works now. So yay... There goes an hour of my time. >.> Damn it coding... lol.
You would like to use this operator:
XMVECTOR XM_CALLCONV operator+ (FXMVECTOR V1, FXMVECTOR V2);
I think you have hidden it somehow like this:
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.