Stroustrup Chapter 4, Exercise 2

A

arnuld

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top