From: doomster@knuut.de   
      
   egg1nog@googlemail.com wrote:   
   > template   
   > class Graph {   
   > public:   
   > struct Edge {   
   > NodeIndex lo, hi;   
   > EdgeData *data;   
   >   
   > Edge() : lo(0), hi(0), data(0) {}   
   > } ;   
   [...]   
   > std::list::iterator works;   
   >   
   > int fred;   
   >   
   > std::list::iterator help;   
   [...]   
   > } ; // Graph   
   [...]   
   > Here is the error message when graph-test.cc #includes it   
   > In file included from graph-test.cc:1:   
   > graph.hh:29: error: type ‘std::list NodeIndex>::Edge, std::allocator NodeIndex>::Edge> >’ is not derived from type ‘Graph NodeIndex>’ graph.hh:29: error: expected ‘;’ before ‘help’   
      
   Edge indirectly depends on a template parameter via its data   
   member. For the same reason, std::list depends on the template   
   parameter. Now, if you refer to something inside that dependent type,   
   you must tell the compiler that it is a type, it could also be a   
   function or an instance. Note that the compiler wont guess that from   
   the class template std::list, because (at least in theory) there could   
   be a specialization where iterator refers to something else. For that   
   reason, the line needs to be   
      
    typename std::list::iterator help;   
      
   so that the compiler knows that iterator is a type.   
      
   > Note that my first use of iterator works. What is the matter with   
   > std::list::iterator that is not the matter with std::list >::iterator ?   
      
   Note that this behaviour is relatively new. Many compiler used to   
   guess from the context whether this was a type, which worked in most   
   cases but was not standard-compliant. For that reason, you will see   
   examples without the typename in many books, especially older ones,   
   that cease to compile with recent compilers.   
      
   Greetings!   
      
   Uli   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|