【问题标题】:template <class ... Args> void operator()( Args && ... args ) shows compile error "Class" missing tagtemplate <class ... Args> void operator()( Args && ... args ) 显示编译错误“Class”缺少标签
【发布时间】:2017-01-27 22:55:30
【问题描述】:

我试图在 Visual Studio 2012 中编译一个库,该库最初是用 C++ 为 Visual Studio 2015 编写的。我有一个错误提示 'class' missing tag

错误消息的屏幕截图

显示编译错误的类的代码。

template <class T>
class construct
{
   public:
      template <class ... Args>
      void operator()( Args && ... args );
      T * operator->()
      {
         if( !itsValid )
            throw Exception("Object must be initialized prior to accessing members");

         return itsPtr;
       } 

       T * ptr()
       {
           return operator->();
       }

   private:
      template <class A, class B> friend struct ::cereal::memory_detail::LoadAndConstructLoadWrapper;

      construct( T * p ) : itsPtr( p ), itsValid( false ) {}
      construct( construct const & ) = delete;
      construct & operator=( construct const & ) = delete;

      T * itsPtr;
      bool itsValid;
};

由于 C++ 编译器版本不同,可能会出现此问题。 Visual Studio 2012 使用 C++0x,Visual Studio 2015 使用 C++11。

非常感谢任何关于如何编译 Visual Studio 2012 的建议。

【问题讨论】:

  • C++11 的实现非常参差不齐,在 VS2012 中几乎无法使用,在 VS2013 中处于边缘地位。一般来说,向后移植 C++11 代码是一项 Sysiphean 任务。 This question/answer 可能会有所帮助。

标签: c++ visual-studio c++11


【解决方案1】:

您遇到的错误很像在代码中使用可变参数模板的结果:http://en.cppreference.com/w/cpp/language/parameter_pack

访问 MSDN 表明他们首次出现在 VS 2013 中:https://msdn.microsoft.com/en-us/library/dn439779(v=vs.120).aspx

如果您必须剥离语言结构来降级编译器,那么您将面临长期的挑战。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 2016-06-11
    相关资源
    最近更新 更多