Afficher un message
Vieux 18/10/2007, 08h25   #3
Ulrich Eckhardt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Method In Templated Super/Parent Called From Templated Derived/Child

Note: f'up to clc++, there is nothing win32-related here.

VirGin wrote:
> I have a class template (or template class, depending on how one was
> taught). I have a class that is derived from the template class. I
> have a method in the parent that is overloaded in the child. If the
> child is unable to process the data being operated on, I want it to
> either return control to the parent or call the parent's version of
> the method. Since templates are involved, I'm unsure of the best way
> of doing this. What are some of the ways of doing this?
>
> Wow, that isn't clear at all.
>
>
> Parent Class:
> template <typename DrvdCls> class TheParentClass
> {
> void TheMethod(void);
> ...
> template <typename DrvdCls> inline void
> TheParentClass<DrvdCls>::TheMethod(void)
> {
> blah.. blah
> }
> }


This code is broken:
1. Missing semicolon at the end. This might seem irrelevant, but it shows
that this is not the code you tried to compile.
2. The syntax for definition of TheMethod inside the class is wrong.
3. Not an error, but an empty parameter list in C++ means no parameters. The
void is not necessary.

> Derived Class:
> class TheKid:public TheParentClass<TheKid>
> {
> void TheMethod(void);
> }


4. Derivation means ISA relationship. Your code says that TheKid is a
TheParentClass. I'd simply drop the term parent/child and substitute them
for base/derived. This is not a C++ error though.

> Using the above format, I want to call TheParentClass::TheMethod from
> within TheKid::TheMethod.
>
> Does that make sense? If so, what are different ways I could
> accomplish this.


Well, then do it! However, for name resolution in template classes, the
baseclass is not(!) considered normally. There are two ways around this:

// explicitly invoke baseclass
TheParentClass<TheKid>::TheMethod();
// trigger normal name lookup
this->TheMethod();


> BTW, the way I did it the first time generated a 'requires template
> argument list' error


Well, that is another point towards #1 above. Show the real code. Show the
real error message. Without real information it's hard to .

Uli

--
Sator Laser GmbH
Geschäftsführer: Ronald Boers, Amtsgericht Hamburg HR B62 932

  Réponse avec citation
 
Page generated in 0,05113 seconds with 9 queries