在c ++ 14工作草案中,N3797声明定义如下:
declaration-seq:
declaration
declaration-seq declaration
declaration:
block-declaration
function-definition
template-declaration
explicit-instantiation
explicit-specialization
linkage-specification
namespace-definition
empty-declaration
attribute-declaration
block-declaration:
simple-declaration
asm-definition
namespace-alias-definition
using-declaration
using-directive
static_assert-declaration
alias-declaration
opaque-enum-declaration
alias-declaration:
using identifier attribute-specifier-seq_opt= type-id;
simple-declaration:
decl-specifier-seq_opt init-declarator-list_opt;
attribute-specifier-seq decl-specifier-seq_opt init-declarator-list;
static_assert-declaration:
static_assert (constant-expression,string-literal);
empty-declaration:
;
attribute-declaration:
attribute-specifier-seq;
我认为它是explicit-instantiation
,但我错了。 int a;
属于什么类型的声明?
答案 0 :(得分:2)
explicit-instantiation 是一个与模板相关的声明,其中模板类通过声明显式地为特定类型实例化。示例(来自§14.7.2草案N3337)
template<class T> class Array { void mf(); };
// explicit instantiation of Array template class for char
// leads to all functions being instantiated too
template class Array<char>;
// explicit instatiation of only the member function mf for int
template void Array<int>::mf();
int a;
是一个简单声明,就像Joachim在评论中提到的那样。