jir*_*iro 1 c++ directx operator-overloading
所以我回到图形编程,我正在使用的书(Frank Luna的3D游戏编程与DirectX 11),使用不再支持的xnamath.h.我已将其更改为使用DirectXMath.h,看似没有任何问题.但是,当我重载ostream <<运算符以使用XMVECTOR时,似乎存在问题.当我尝试使用cout打印XMVECTOR对象时,我收到此错误:
Error 1 error C2280: 'std::basic_ostream<char,std::char_traits<char>>::basic_ostream(const std::basic_ostream<char,std::char_traits<char>> &)' : attempting to reference a deleted function
Run Code Online (Sandbox Code Playgroud)
此程序中只有一个文件(main.cpp):
#include <Windows.h>
#include <DirectXMath.h>
#include <iostream>
using namespace DirectX;
using namespace std;
// Overload the "<<" operators so that we can use cout to output XMVECTOR objects
ostream& operator<<(ostream os, FXMVECTOR v);
int main() {
cout.setf(ios_base::boolalpha);
// Check support for SSE2 (Pentium4, AMD K8, and above
if (!XMVerifyCPUSupport()) {
cout << "DirectX Math not supported" << endl;
return 0;
}
XMVECTOR n = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f);
XMVECTOR u = XMVectorSet(1.0f, 2.0f, 3.0f, 0.0f);
XMVECTOR v = XMVectorSet(-2.0f, 1.0f, -3.0f, 0.0f);
XMVECTOR w = XMVectorSet(0.707f, 0.707f, 0.0f, 0.0f);
// Vector addition: XMVECTOR operator +
XMVECTOR a = u + v;
cout << a;
}
ostream& operator<<(ostream os, FXMVECTOR v) {
XMFLOAT3 dest;
XMStoreFloat3(&dest, v);
os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ")";
return os;
}
Run Code Online (Sandbox Code Playgroud)
我有一种感觉,我正在弄乱操作员超载,但我现在还不确定.我在网上找不到任何类似的问题,但我希望我只是忽略了一些非常基本的东西.任何建议将被认真考虑.
问题出在这一行:
ostream& operator<<(ostream os, FXMVECTOR v) {
Run Code Online (Sandbox Code Playgroud)
将其更改为
ostream& operator<<(ostream& os, FXMVECTOR v) {
Run Code Online (Sandbox Code Playgroud)
第一行尝试ostream使用复制构造函数制作副本.这是不允许的.