I'm really confused. I am reading TC ++ PL by Bjarne Stroustrup (special edition, 19th edition - September 2010). Let me quote part of the book, highlighting my confusion:
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 you can see from these examples, a declaration can do more than just associate a type with a name. Most of these statements are also definitions; that is, they also define the entity for the name to which they refer. For ch, this object is the appropriate amount of memory to be used as a variable - this memory will be allocated. For the day, this is a given function. For the constant pi, this value is 3.1415926535897932385. For date, this object is a new type. For a point, it is a complex of types, so that a point becomes a synonym for complex . Of the above ads, only these Definitions:
double sqrt(double); extern int error_number; struct User; typedef complex<short> Point <-- WTF;
Isn't this a bold sentence contrary to the list below? Is typedef just a declaration or also a definition? Is this a mistake in the book?
source share