Reputation: 6597
I am trying to use Boost's lexical_cast for my C++ project but am running into compilation errors using Visual Studio 2010 Professional.
Error is as follows:
1> VLGUI_Frame.cpp
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(54): error C2143: syntax error : missing ')' before 'constant'
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(54): error C2143: syntax error : missing ';' before 'constant'
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(54): error C2988: unrecognizable template declaration/definition
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(54): error C2059: syntax error : 'constant'
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(54): error C2059: syntax error : ')'
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(72): error C2143: syntax error : missing ';' before '{'
1>c:\users\dev\external\boost_1_46_1\boost\throw_exception.hpp(72): error C2447: '{' : missing function header (old-style formal list?)
1>
1>Build FAILED.
and here is the code that is using lexical_cast (it is not related, but who knows it may help)
#include "boost/lexical_cast.hpp"
...
std::string Frame::toString( )
{
std::string str = "";
try
{
str = VLString::combine( 12,
m_Name.c_str( ),
" : Dimensions[",
boost::lexical_cast< std::string >( m_Rect.width ).c_str( ),
",",
boost::lexical_cast< std::string >( m_Rect.height ).c_str( ),
"] : Loc[",
boost::lexical_cast< std::string >( m_Rect.x ).c_str( ),
",",
boost::lexical_cast< std::string >( m_Rect.y ).c_str( ),
"] : NumChildren[",
boost::lexical_cast< std::string >( m_Children.size( ) ).c_str( ),
"]" );
}
catch( boost::bad_lexical_cast & )
{
str = VLString::combine( 2,
m_Name.c_str( ),
" : lexical_cast failed" );
}
return str;
}
Unfortunately I do not have enough experience with Boost to diagnose this problem on my own. I did the obligatory google-ing with no results.
Thank you for any help.
Upvotes: 1
Views: 3777
Reputation: 5892
I had the exact same error because some one decided it would be cool to create a macro called throw_exception.
This then caused a build failure if the header containing this #define was ever included before the boost header. This is because:
template<typename E> BOOST_ATTRIBUTE_NORETURN inline void throw_exception(E const & e)
Would have "throw_exception" replaced with the macro creating invalid code.
Upvotes: 0
Reputation: 106549
It looks like the actual error lies in the header before <boost/throw_exception.hpp>
. E.g. your translation unit contains something like
#include "myheader.hpp"
#include <boost/throw_exception.hpp>
//You translation-unit specific code in here
where "myheader.hpp"
contains something like
class MyClass
{
//Members
} // <-- Note missing semicolon!
Generally speaking, if you can't even compile a header file, and you get a error C2447: '{' : missing function header (old-style formal list?)
, you usually need to check the header before the one where the error occurs.
Finally, you can eliminate this problem by using a standardized header include order inside each translation unit. I usually use this order:
If you use this order, the bug will show up in your own code if it exists, rather than in the bowels of some third party header you have no control over.
Upvotes: 7