olli wrote:
I have a library which I want to build on msvc++ 2005. however the
compiler generates the following warnings and errors concerning the
following source snippet:
template <class EOT>
class eoSelectivePopulator : public eoPopulator<EOT>
{
public :
using eoPopulator< EOT >::src;
eoSelectivePopulator(const eoPop<EOT>& _pop, eoPop<EOT>& _dest,
eoSelectOne<EOT>& _sel)
: eoPopulator<EOT>(_pop, _dest), sel(_sel)
{ sel.setup(_pop); };
/** the select method actually selects one guy from the src pop */
const EOT& select() {
return sel(src);
}
private:
eoSelectOne<EOT>& sel;
};
---
output is:
eopopulator.h(192) : warning C4346: 'EOT::Fitness' : dependent name is
not a type
prefix with 'typename' to indicate a type
The code you've shown is not the source of this error (clearly, since
there's no mention of EOT::Fitness in this code).
I'm going to assume that this is code you're porting from VC7 (2002) or
earlier. The issue here is that, as the error message explains, a
dependent name is not a type name. So what's a dependent name? Roughly
speaking, it's a name whose definition depends on one or more template
parameters. In this case, EOT::Fitness is a dependent name.
Early C++ compilers, like VC6 and VC7 would accept such names as being
type names, but that causes problems with other constructs where the name
isn't really a type. So, the C++ standard mandates that a dependent name
is never a type name unless you explicitly state that it is. The way you
do that is by using the 'typename' keyword.
Generally, you solve this error (and make your code standard complaint)
by simply adding the typename keyword before the name, so replace
"EOT::Fitness" with "typename EOT::Fitness".
-cd