Stroustrup Chapter 4, Exercise 2

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

  1. arnuld

    arnuld Guest

    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
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. arnuld

    Stroustrup chapter 3 - 3.6

    arnuld, Nov 5, 2006, in forum: C++
    Replies:
    4
    Views:
    414
    arnuld
    Nov 5, 2006
  2. arnuld
    Replies:
    14
    Views:
    1,026
    Alf P. Steinbach
    Nov 11, 2006
  3. arnuld

    Stroustrup: chapter 4

    arnuld, Mar 4, 2007, in forum: C++
    Replies:
    13
    Views:
    660
    benben
    Mar 5, 2007
  4. arnuld
    Replies:
    0
    Views:
    515
    arnuld
    Mar 5, 2007
  5. arnuld
    Replies:
    4
    Views:
    523
    mlimber
    Mar 5, 2007
Loading...

Share This Page