473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Method In Templated Super/Parent Called From Templated Derived/Child

Hola Folks,

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 DrvdClsclass TheParentClass
{
void TheMethod(void);
...
template <typename DrvdClsinline void
TheParentClass<DrvdCls>::TheMethod(void)
{
blah.. blah
}
}

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

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.

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

anyway, thanx in advance
-V-

Oct 17 '07 #1
2 1856


"VirGin" <vi******@gmail.comwrote in message
news:11**********************@t8g2000prg.googlegro ups.com
Using the above format, I want to call TheParentClass::TheMethod from
within TheKid::TheMethod.
TheParentClass is the class template (i.e. not actually a class, but a
template for one), and as you hinted at earlier you need to use the template
class. So you should use:
TheParentClass<TheKid>::TheMethod();

BTW, the way I did it the first time generated a 'requires template
argument list' error
This is because to call a method you need to call it on a template class,
not a class template and to go from a class template to a template class you
need to provide an argument list (<TheKidin this case).

Oct 17 '07 #2
Hola Rasmus,

On Oct 17, 3:05 am, "Rasmus Johansen" <rasmus_noert...@hotmail.com>
wrote:
Using the above format, I want to call TheParentClass::TheMethod from
within TheKid::TheMethod.
TheParentClass is the class template (i.e. not actually a class, but a
template for one), and as you hinted at earlier you need to use the template
class. So you should use:
TheParentClass<TheKid>::TheMethod();
BTW, the way I did it the first time generated a 'requires template
argument list' error
This is because to call a method you need to call it on a template class,
not a class template and to go from a class template to a template class you
need to provide an argument list (<TheKidin this case).
Ouch!

That was the second thing I did. Unfortunately it failed. However, it
failed because of Programmer Error. It turned out that I did not type
the name of the child class correctly when I added:
TheParentClass<TheKid>::TheMethod() to TheMethod.

The error that I received was about non-static member functions. I
guess I was too tired to realize what was happening.

Adding TheParentClass<TheKid>::TheMethod() to TheKid::TheMethod()
works.

Thank You!
-V-

Oct 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Robin Forster | last post by:
I have two classes: aule_gl_window (parent class) and aule_button (sub class) I want to call the super class (parent) constructor code from the sub class constructor.
5
by: Paul | last post by:
Hi all, Here is what I am trying to do. I have a parent class calling a child class. when one function in child class is called, i need to call parent class' function. How can I get parent class'...
6
by: cppaddict | last post by:
Hi, I know that C++ does not have an explicit super() constructor for calling a Base class constructor from a Derived class's constructor, but my understanding is that C++ implements this...
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
6
by: jalkadir | last post by:
Let's say that I have this class: class Parent{ private: char* str; public: const char* getStr(){return str;} }; And then I create a child class class Child{ private: std::string str;...
6
by: Squeamz | last post by:
Hello, Say I create a class ("Child") that inherits from another class ("Parent"). Parent's destructor is not virtual. Is there a way I can prevent Parent's destructor from being called when a...
10
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below is pretty simple. Calling Talker() in the parent returns "Parent", and calling Talker() in the child returns "Child". I'm wondering how I can modify the code so that a call to the...
3
by: 7stud | last post by:
When I run the following code and call super() in the Base class's __init__ () method, only one Parent's __init__() method is called. class Parent1(object): def __init__(self): print...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.