理解できないコンパイル時エラーで立ち往生しています。boost::optional
コードで使用しようとしましたが、インクルードするとすぐboost/optional.hpp
にプロジェクトをビルドできなくなりました。この include ステートメントをコメントアウトすると、機能します。クラス ヘッダーの include ステートメントだけです (以下の完全なboost::optional
ヘッダーを参照)。コンパイラ エラーはC2143 syntax error: missing ',' before '<'
、別の Boost ヘッダーで発生するものですboost/utility/compare_pointees.hpp
(以下の GitHub リンクを参照)。同じプロジェクトのように、Boost の他のものもうまく使用しboost::filesystem::path
ているので、Boost ディストリビューション自体に問題はないはずです。
ここに私の環境があります:Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3
とboost 1.62.0
. 私はサードパーティのライブラリC++ REST SDKも使用しています。それ以外はすべて C++ 標準ライブラリのものです。
私のヘッダーは次のようになります。boost::optional<size_t>
戻り値の型として新しいメソッドを追加したい。
#pragma once
#include <boost/optional.hpp> // <==== ERROR
// C++ REST SDK
#define _TURN_OFF_PLATFORM_STRING
#include <cpprest/http_listener.h>
#include <cpprest/http_msg.h>
namespace SANDBOX::REST
{
class HttpGetHandler
{
public:
virtual void HandleHttpGetRequest(web::http::http_request request) = 0;
};
}
コンパイラ エラーが報告される場所は、Boost ヘッダーboost/utility/compare_pointees.hpp
の 36 行目です。このファイルの全内容は、GitHub のhttps://github.com/boostorg/utility/blob/boost-1.62.0で確認できます。 /include/boost/utility/compare_pointees.hpp
コンパイラの出力には、次のメッセージしか表示されません。
1>D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<'
1> D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled
1>D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(59): error C2143: syntax error: missing ',' before '<'
1> D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
Boost ライブラリの問題ではありません。しかし、クラスやプロジェクトの設定の何が問題なのか、どうすればわかりますか?
PS プロジェクトでこれらの最も基本的なヘッダーとソース ファイルを使用しても、動作を再現できます。
ヘッダファイルTest.h
:
#pragma once
#include <boost/optional.hpp>
ソースファイルTest.cpp
:
#include "../include/Test.h"