VisualStudio のデバッグビルドではまった
あるライブラリを使おうとヘッダファイルを include したら、意味不明なエラーが出た。
(×) | 1 | error C2059: 構文エラー : '文字列' |
(×) | 2 | error C2091: 関数は関数を返せません。 |
(×) | 3 | error C2802: 静的なメンバ 'operator new' に仮引数リストがありません。 |
1 行追加しただけ (include しただけ) なのに何故?
問題のエラー箇所を見ると、
void* operator new(size_t size);
関数返してないし!
静的なメンバじゃないし!
1 時間くらい悩んでやっと分かった。
#include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #include <foo.h> // 問題のヘッダファイル
new が DEBUG_NEW に変わってるやん _| ̄|○
#include "stdafx.h" #include <foo.h> // ここへ移動させれば OK #ifdef _DEBUG #define new DEBUG_NEW #endif