# Stroustrup Chapter 4, Exercise 2

Discussion in 'C++' started by arnuld, Mar 5, 2007.

1. ### arnuldGuest

Stroustrup has a table in section 4.9 of declarations and
definitions. he asks to write a similar table but in opposite sense:

char ch; // declaration with definition

he asks to do the opposite as an exercise which is writing it as a
"declaration without definition". please check whether i am right or
wrong:

1. char ch; - extern char ch;

2. string s; - extern string s;

3. int count = 1; - extern int count;

4. const double pi = 3.14159...... - extern const double pi;

5. extern int error_number; - int error_number; or
int error_number = 1;

6. const char* name = "Nijal" - extern const char* name;

7. const char* season[] = { "spring", "summer", "fall", "winter" };

- extern const char* season[];

8. struct Date { int d, m, y; }; - struct Date;

9. int day(date* p) { return p->d };

- int day(Date*);

10. double sqrt(double); - double sqrt(double) { }

11. template<class T>T abs(T a) { return a < 0? -a : a; }

- template<class T>T abs(T a);

// just guessed for it, as i know nothing about templates

12. typedef complex<short> Point;

// i have NO idea about what is this.

13. struct User; - struct User {}

14. enum Beer { carlsberg, Tuborg, Thor };

- enum Beer;

15. namespace NS { int a; }

- namespace NS;

arnuld, Mar 5, 2007