所以我回到圖形編程中,並且我用作參考的書(Frank Luna的DirectX 11 3D遊戲編程)使用不再支持的xnamath.h。我已經改變它使用DirectXMath.h貌似沒有任何問題。但是,當我將運算符過載到運算符XMVECTORs時,似乎有問題。當我嘗試用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
只有一個文件,這個程序(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;
}
我有一種感覺,我這讓運營商負擔過重,但我現在還不確定。我在網上找不到任何類似的問題,但我希望我只是忽略了一些基本的東西。任何建議將被認真考慮。
流無法複製。你也試圖返回一個局部變量的引用。快速瀏覽[運算符重載](http://stackoverflow.com/questions/4421706/operator-overloading)將提供正確的簽名。 – chris