开发者

Statement from ISO standard $3.1 : 1st point from n3242 doc

Statement from ISO standard $3.1 : 1st point

n3242 Says:

A declaration (Clause 7) may introduce one or more names into a translation unit or redeclare names introduced by previous declarations. If so, the declaration specifies the interpretatio开发者_StackOverflow社区n and attributes of these names. A declaration may also have effects including: — a static assertion (Clause 7), — controlling template instantiation (14.7.2), — use of attributes (Clause 7), and — nothing (in the case of an empty-declaration).

ISO 2003 DOC says:

A declaration (clause 7) introduces names into a translation unit or

redeclares names introduced by previous declarations. A declaration

specifies the interpretation and attributes of these names.

can any one explain what is the difference .

They said "A declaration may also have effects including: " ...CAn any one explain what are these effects in terms of Programming

Please explain these effects in Programming way(with an example program)?


I believe it just that some new features have changed the way a declaration works - in the small details.

For example, this does't just introduce some names, but also affects compilation of the code.

struct A
{
  int x;
};

struct B
{
    A  a;
    static_assert(sizeof(a) > 10, "Wrong member size");
};

We also have the empty declaration (which I belive can only be used inside a class):

struct C
{
  void f()
  { };      // Semicolon here is allowed, but is an empty declaration
};

The empty declaration is a declaration that does not introduce a name (because it is empty).

Figured out the "affects template instantiation" as well, I think:

template<class T>
class X
{
   // some members
};

extern template class X<int>;
extern template class X<char>;

Tells the compiler that X<int> and X<char> will be instantiated somewhere else and does not have to be generated here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜