什么是模板构造函数继承的标准符合语法? [英] What is the standard conform syntax for template constructor inheritance?
问题描述
GCC 4.8.1接受
GCC 4.8.1 accepts
template <typename T>
class Subclass : public Baseclass<T>
{
public:
using typename Baseclass<T>::Baseclass;
};
但MSVC没有。另一方面,MSVC接受
but MSVC does not. On the other hand, MSVC accepts
template <typename T>
class Subclass : public Baseclass<T>
{
public:
using typename Baseclass::Baseclass;
};
但GCC没有。然后,我在这个问题中看到了另一种声明: c ++ 11继承模板构造函数
but GCC does not. Then I've seen another kind of declaration in this questions: c++11 inheriting template constructors
template <typename T>
class Subclass : public Baseclass<T>
{
public:
using typename Baseclass::Baseclass<T>;
};
b
for which MSVC warns about an "obsolete declaration style" and GCC says
prog.cpp:8:24: error: ‘template<class T> class Baseclass’ used without template parameters
using typename Baseclass::Baseclass<T>;
我认为第一个例子是标准的符合语法。直观地,它看起来很对我。
I thought the first example would be the standard conform syntax. Intuitively, it looks right to me.
什么是c ++ 11标准符合语法?
What is the c++11 standard conform syntax?
推荐答案
答案有点埋在标准中。使用声明定义为(7.3.3):
The answer is a bit buried in the standard. A using declaration is defined as (7.3.3):
using [typename] nested-name-specifier unqualified-id;
nested-name-specifier
一些步骤转换为 simple-template-id
(定义为
The nested-name-specifier
resolves after some steps into simple-template-id
which is defined as
template-name < [template-argument-list] >
简而言之,符合标准的语法是
In short, the standard conforming syntax is
template <typename T>
class Subclass : public Baseclass<T>
{
public:
using typename Baseclass<T>::Baseclass;
};
这篇关于什么是模板构造函数继承的标准符合语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!