c++ - Boost 中的编译错误 throw_exception.hpp

标签 c++ visual-studio-2010 boost

我正在尝试将 Boost 的 lexical_cast 用于我的 C++ 项目,但在使用 Visual Studio 2010 Professional 时遇到编译错误。

错误如下:

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.

这是使用 lexical_cast 的代码(它不相关,但谁知道它可能会有所帮助)

#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;
}

不幸的是,我没有足够的 Boost 经验来自行诊断这个问题。我进行了强制性的谷歌搜索,但没有结果。

感谢您的帮助。

最佳答案

看起来实际错误在于<boost/throw_exception.hpp> 之前的 header 中.例如。你的翻译单元包含类似

#include "myheader.hpp"
#include <boost/throw_exception.hpp>

//You translation-unit specific code in here

哪里"myheader.hpp"包含类似的东西

class MyClass
{
    //Members
}    // <-- Note missing semicolon!

一般来说,如果你连一个头文件都编译不了,你会得到一个error C2447: '{' : missing function header (old-style formal list?)。 ,你通常需要检查发生错误的标题之前的标题。

最后,您可以通过在每个翻译单元中使用标准化的 header 包含顺序来消除此问题。我通常使用这个顺序:

  • C 标准库
  • C++ 标准库
  • C 第三方库
  • C++ 第三方库
  • 我的标题

如果您使用此命令,则该错误将显示在您自己的代码中(如果存在),而不是出现在您无法控制的某些第三方 header 的内部。

关于c++ - Boost 中的编译错误 throw_exception.hpp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5864862/

相关文章:

c++ - 在 C 中求解多项式系统(4,二阶)

带有可选参数的 C++ 函数

c# - 如何在 ASP 中使用 JavaScript 使用 DropDownList 的值填充 TextArea

c++ - 使用 SCons 跨平台构建 Boost

c++ - CUDA 全局内存

c - 传递的参数更改值

c++ - 如何使用#error 指令为用户提供指向有用信息的指针?

c++ - 在 C++ 中使用 boost::split 的段错误(核心转储)

c++ - 序列化作为一种​​IPC机制?

c++ - 为什么在这种情况下重载决议不明确?