简体   繁体   中英

Unable to compile nsgmls with template erros

I am a avid emacs user, and want to use sgml markup check routine. I was naturally headed towards nsgmls, and downloded the source code to compile it.

However, there was a strange error coming from the compiler with the followings.

./../include/RangeMap.h:57: error: type ‘Vector<RangeMapRange<From, To> >’ is not deri  ved from type ‘RangeMapIter<From, To>’
./../include/RangeMap.h:57: error: expected ‘;’ before ‘ptr_’
./../include/RangeMap.h: In member function ‘Boolean RangeMapIter<From, To>::next(From&, From&, To&)’:
./../include/RangeMap.h:47: error: ‘ptr_’ was not declared in this scope

I know that some times compiler gets disgruntled by template and typename madness, however the codes seems to have already used typename correctly within the code.

Here are the cope snippets that arouses these errors.

template<class From, class To>                                                                                                                                                         
class RangeMapIter {                                                                                                                                                                   
public:                                                                                                                                                                                
  RangeMapIter(const RangeMap<From,To> &map);                                                                                                                                          
  Boolean next(From &fromMin, From &fromMax, To &toMin) {                                                                                                                              
    if (!count_)                                                                                                                                                                       
      return 0;                                                                                                                                                                        
    else {                                                                                                                                                                             
      fromMin = ptr_->fromMin;                                                                                                                                                         
      fromMax = ptr_->fromMax;                                                                                                                                                         
      toMin = ptr_->toMin;                                                                                                                                                             
      ptr_++;                                                                                                                                                                          
      count_--;                                                                                                                                                                        
      return 1;                                                                                                                                                                        
    }                                                                                                                                                                                  
  }                                                                                                                                                                                    
private:                                                                                                                                                                               
  size_t count_;                                                                                                                                                                       
  typename Vector<RangeMapRange<From,To> >::const_iterator ptr_;                                                                                                                       
};

Can anybody help me hash out those errors?

This error message is given by GCC in the wrong order of both type names. (but it apparently fixed this in the latest version). It is meant to say that Vector<RangeMapRange<From,To> >::const_iterator was not found to be a type name. The underlying cause of this diagnostic is that the code is parsed as an access-declaration , which has the following syntax

::[opt] nested-name-specifier template[opt] unqualified-id ;

An example of that syntax

struct A {
  int a;
};

struct B : A {
  // equivalent to: using A::a;
  A::a;
};

In C++11 this access-declaration construct was taken out of the specification and it was deprecated in C++03. But since the compiler still supports parsing it, when the Vector<RangeMapRange<From,To> >::const_iterator is not found to be a type, it will be taken as a name to be declared in an access-declaration (so the parser moves forward across the type specifier section). Hence according to the above syntax, after the unqualified-id which in this case is const_iterator (and in my example was a ), it wants to see a semicolon and it wants that Vector<RangeMapRange<From, To> > is a base class of RangeMapIter<From, To> , but confusingly the diagnostic it gives has it the other way around.

Check your names and make sure the type exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM