char ch;string s;int count = 1;const double pi = 3.1415926535897932385;extern int error_number;const char* name = "Njal";const char* season[] = { "spring","summer","fall","winter" };struct Date { int d,m,y; };int day(Date* p) { return p->d; }double sqrt(double);template<class T> T abs(T a) { return a<0 ? -a : a; }typedef complex<short> Point;struct User;enum Beer { Carlsberg,Tuborg,Thor };namespace NS { int a; }
As can be seen from these examples,a declaration can do more than simply
associate a type with a name. Most of these declarations are also deFinitions;
that is,they also define an entity for the name to which they refer. For ch,
that entity is the appropriate amount of memory to be used as a variable – that
memory will be allocated. For day it is the specifIEd function. For the
constant pi,it is the value 3.1415926535897932385. For Date,that entity is
a new type. For Point it is the type complex so that Point becomes a
synonym for complex. Of the declarations above,only these are not also
deFinitions:
double sqrt(double);extern int error_number;struct User;typedef complex<short> Point <-- WTF;
大胆的句子是不是与下面给出的列表冲突了? typedef只是一个声明还是一个定义?这是书中的错误吗?
解决方法 虽然我对此完全感到困惑.标准很清楚. Typedef只是一个声明.不定义.3.1-2
A declaration is a deFinition unless
it declares a function without
specifying the function’s body (8.4),
it contains the extern specifIEr
(7.1.1) or a linkage-specification24)
(7.5) and neither an initializer nor a
function-body,it declares a static
data member in a class declaration
(9.4),it is a class name declaration
(9.1),or it is a typedef
declaration (7.1.3),a
using-declaration (7.3.3),or a
using-directive (7.3.4).
编辑:哦,我才明白为什么.您可以键入一个声明,因此typedef必须是一个声明本身.
总结以上是内存溢出为你收集整理的c – typedef是一个定义吗?全部内容,希望文章能够帮你解决c – typedef是一个定义吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)