Re: error: 'cit' was not declared in this scope

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi John,

Thats perfect and solved my problem, thank you very much. I now have a better understanding of what the compiler is expecting. The compiler could certinaly do with a more explicit error message in this scenario, perhaps something like:-

test.cpp:30: error: The item base_type::const_iterator is not known as a type

certainly would have helped

I did not go with the second "using" option as I thought it was less readable than being explicit about what is being called - at least for me it worked better that way.

Regards,

Gerry

----- Original Message ----- From: "John S. Fine" <johnsfine@xxxxxxxxxxx>
To: "Gerry Sweeney" <gerry.sweeney@xxxxxxxxxxxxxxxx>
Cc: <gcc-help@xxxxxxxxxxx>
Sent: Tuesday, December 29, 2009 7:49 PM
Subject: Re: error: 'cit' was not declared in this scope


You are focusing on the second error, but that was just a consequence of the first.

During the initial parsing, the compiler doesn't know that types from the base class are types, because it doesn't know what the base class will be until it has the template actuals.

You can tell it that types are types using the typename keyword in each place where you use them.

I think that is a bad style, and it is better to bring such types into the current class with a typedef as in

      typedef std::map<Key, Value> base_type;
      typedef typename base_type::const_iterator const_iterator;
...
      const_iterator cit = base_type::find(key);

But in similar style, I also think "using" is better than individual overrides for functions that should be inherited from the base class:

      typedef std::map<Key, Value> base_type;
      typedef typename base_type::const_iterator const_iterator;
      using base_type::find;
...
      const_iterator cit = find(key);




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux