Question

On page 172, Stroustrup is doing something like so:

  namespace Parser {   //interface for users
    double expr(bool);
  }

  namespace Parser { //interface for implementers
    double prim(bool);
    double term(bool);
    double expr(bool);

    using Lexer::get_token;
    <SNIP>
  }

Q1. does this imply that the first namespace is being inserted into (as an example) user.h and included from main.cpp - the driver; the second namespace into implementer.h and included from parse.cpp? Is this why he says:

"compiler doesn't have sufficient information to check the consistency of the two definitions of the namespace"

  • because both implementer.h and user.h can't be included into "Parser implementation"(parse.cpp)?

172.png 173.png

On page 174, he has:

  namespace Parser {   //interface for implementers
    // ...
    double expr(bool);
   // ...
  }

  namespace Parser_interface { //interface for users
    using Parser::expr;
  }

Is upper namespace going into implementer.h and lower one into user.h

In his "dependency graph" is he restating the obvious: that when Make is run, any change to "Parser"(parser.cpp/implementer.h) will result in driver/main.cpp being rebuilt - unnecessarily?

174.png

Was it helpful?

Solution

http://groups.google.com/group/alt.comp.lang.learn.c-c++/browse_thread/thread/3be9f35f2969f311/0d418ec6138a7e58#0d418ec6138a7e58

(the part about compiler consistency is wrong and the above thread states why: Yes, the implementation can and should do that, but the checking of consistency only works to a certain extent. If user.h uses things that are not declared there, you will get a diagnostic. If you have "double expr(bool);" declared in one place and "float expr(bool);" in another, the compiler should also give you a diagnostic. However, if you change the second one to "float expr(int);", then this is just an overload which is perfectly legal C++. - Ulrich Eckhardt)

OTHER TIPS

I believe the answers to all three your questions are "yes"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top