On Fri, 2007-04-27 at 14:46 -0400, Jerry Feldman wrote:
I have a case where the compiler is giving me an error:
./FOO.H: In member function
Bar<ItemType>::operator()(ItemType&)':
./FOO.H:447: error: `i_key' was not declared in this scope
I think you need to use this->i_key instead of i_key.
The logic is this. C++ looks up nondependent names like i_key as soon as
they are encountered. But it can't find i_key because it is possible for
you to create an explicit specialization of FuBar in which i_key is not
of type ThisType const &. Using this->i_key delays name lookup to the
point of instantiation of the class, by which time its type will be
known for certain.
No. this->i_key is equivalent to i_key in a member function.
The issue is with the dual template arguments. i_key is defined in the
On Sat, 28 Apr 2007 07:45:41 +0100
John D Lamb wrote:
base class as:
ThisType const & i_key;
But the inheriting class does not include the ThisType template
parameter. The correct solution, as I found out yesterday afternoon is
to refer to i_key as fully qualified:
FuBar::i_key;
The calling function is a member of bar with is defined as:
template <class ItemType>
class Bar : public FuBar
Since this code actually works in the company's other product, I was
looking at some of the compiler options rather than the correct C++
solution. (BTW: type_t is simply a typedef to an enumeration).
Actually there are 4 different classes, where 2 take type_t, 1
std:string, and the fourth, std::vector.
It's amazing how much you look at something and know the solution, but
can't think of it.
--
Jerry Feldman
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9