I'm stuck with a compile-time error which I cannot understand. I try to use boost::optional
in my code, and as soon as I include boost/optional.hpp
I cannot build my project any longer. If I comment this include statement out, it works. I don't even have any actual usage of boost::optional
in my code yet, just the include statement in the class header (see full header below). The compiler error is C2143 syntax error: missing ',' before '<'
which happens in another Boost header boost/utility/compare_pointees.hpp
(see GitHub link below). I also successfully use other stuff from Boost like boost::filesystem::path
in the same project already, so there should be no problem with my Boost distribution as such.
Here is my environment: Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3
and boost 1.62.0
. I also use the third-party library C++ REST SDK, everything else is C++ standard library stuff.
My header looks like this. I want to add a new method with boost::optional<size_t>
as return type.
#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;
};
}
The place, where the compiler error is reported, is in the Boost header boost/utility/compare_pointees.hpp
, line 36. You can view the full content of this file on GitHub under https://github.com/boostorg/utility/blob/boost-1.62.0/include/boost/utility/compare_pointees.hpp
The compiler output shows nothing more than these messages:
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 ==========
It's surely not a problem of the Boost library. But how can I figure out, what's wrong with my classes or project settings?
P.S. I can reproduce the behavior even if I use these most primitive header and source file in my project:
Header file Test.h
:
#pragma once
#include <boost/optional.hpp>
Source file Test.cpp
:
#include "../include/Test.h"
std::binary_function
is deprecated. – WinnipegosisD:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<' 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
– Quincey/std:c++latest
? I understand this switch removes some of the things that will be removed in c++17 and it's possible that Boost (or this particular Boost library) has not adapted yet to that change. If you are using it you should try/std:c++14
and see if it works for you. – Malefic/std:c++latest
to enable C++17 one-line nested namespace definition. If I remove/std:c++latest
, I can useboost::optional
without any problems. Man, that was a great hint! Please enter it as solution and I will upvote it and mark as answer! – Quincey