Re: msvc++ 2005 template question
- From: "Ben Voigt" <rbv@xxxxxxxxxxxxx>
- Date: Wed, 18 Oct 2006 11:37:19 -0500
"olli" <ob@[removethis]numeris.de> wrote in message
news:OfIa3xs8GHA.3760@xxxxxxxxxxxxxxxxxxxxxxx
thanks for your reply, carl. I've done a search trough the whole
solution and EOT::Fitness always appears with typename EOT::Fitness...
the compiler complains exactly about the lines which I have posted.
Strange that there is no EOT::Fitness in there - this confuses me.
No, the compiler encountered trouble instantiating a template you used on
that line. It also told you where to look:
eopopulator.h(205) : see reference to class template
Please show us the area around line 205.
cheers, Oliver
Carl Daniel [VC++ MVP] schrieb:
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
.
- Follow-Ups:
- Re: msvc++ 2005 template question
- From: olli
- Re: msvc++ 2005 template question
- References:
- msvc++ 2005 template question
- From: olli
- Re: msvc++ 2005 template question
- From: Carl Daniel [VC++ MVP]
- Re: msvc++ 2005 template question
- From: olli
- msvc++ 2005 template question
- Prev by Date: Re: msvc++ 2005 template question
- Next by Date: Re: accessing an array of integers from jscript in a vc++ activex/com
- Previous by thread: Re: msvc++ 2005 template question
- Next by thread: Re: msvc++ 2005 template question
- Index(es):
Relevant Pages
|