Re: msvc++ 2005 template question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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


.



Relevant Pages

  • Cannot convert from Type to const Type& error with templates
    ... what other people say before I blame the compiler. ... template<typename F, typename G> ... // Template function to construct compose_t ... // Helper function to form arbitrary predicate ...
    (microsoft.public.vc.language)
  • Re: template copy constructor
    ... This compiler does not consider ... template <typename U> ... as a template copy constructor. ...
    (microsoft.public.vc.language)
  • Re: msvc++ 2005 template question
    ... the compiler complains exactly about the lines which I have posted. ... Carl Daniel schrieb: ... The issue here is that, as the error message explains, a dependent name is not a type name. ... The way you do that is by using the 'typename' keyword. ...
    (microsoft.public.vc.language)
  • Re: code compiles in v6 but not in v7
    ... Since the compiler does not know what T is yet, ... That's what a "dependent name" is. ... VC7insists on being standard conformant and requires you ... to explicitly specify typename. ...
    (microsoft.public.vc.atl)
  • Re: EVC++: compile errors disappear when preprocessor output is on
    ... template <typename T> ... more elaborate template ... Without seeing actual compiler errors I can only guess. ... be that T hasn't appropriate copy constructor. ...
    (microsoft.public.vc.language)