Stricter C++ Compiler - Template Changes

From Appmethod Topics
Jump to: navigation, search

Go Up to Stricter C++ Compiler (Appmethod C++) Index

The C++ compiler no longer allows an explicit template without the 'template <>' prefix. Use the compiler switch -Vbe to allow this. The following example shows this:

template <class>
class foo {
 foo();
};
foo<int>::foo();//Error
template<> foo<int>::foo();//OK

Also, the C++ compiler no longer allows explicit template specialization within a class. Use the compiler switch -Vbx to allow this. For example, the following generates an error:

struct S {};
  struct SP
  {
    template <typename> void foo(const T &) {}
    template <> void foo(const S &) {} // Error
  };

  template <> void SP::foo(const S &) {} //OK

See Also