Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Abstract Classes, Templates and inheritance...

Reply
Thread Tools

Abstract Classes, Templates and inheritance...

 
 
ptkacz@cogeco.ca
Guest
Posts: n/a
 
      08-06-2005
I've got two classes, B and C, each performing essentially the same
functionality, except for the fact that they each operate on a different
data type, and that they each have a class method that has different logic
to work with the respective datatype. I was thinking that I'd create an
abstract template class A, that would be inhereted by both B and C classes.
All that would be left to do then, is implement a single method in B and C,
saving lots of work (except for the headics). My question is, how in
classes B and C, when each inherits A, how does one specify a type to A?

I might have something like:

template <class T>
class A
{
public:
A();
void commonMethod() {... common code ... };
virtual void notSoCommonMethod() = 0;

private:
T* var;
};


class B : public A
{
public:
B() : A<some type>();

void notSoCommonMethod() { ... code working on <some type> ... return; }
};

class C : public A
{
public:
C() : A<another type>();

void notSoCommonMethod() { ... code working on <another type> ...
return; }
};

I could then just code:

B varB;
C varC;

varB.commonMethod();
varC.commonMethod();

varB.notSoCommonMethod();
varC.notSoCommonMethod();

Have I just answered my own question?

Peter
 
Reply With Quote
 
 
 
 
Tobias Blomkvist
Guest
Posts: n/a
 
      08-06-2005
sade:
> saving lots of work (except for the headics). My question is, how in
> classes B and C, when each inherits A, how does one specify a type to A?
>

[snip]
>
>
> class B : public A
> {
> public:
> B() : A<some type>();
>


class B : public A<char>
{
public:
B();

Tobias
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
what is the difference between abstract class and pure abstract class? skishorev@yahoo.co.in C++ 4 05-17-2006 08:07 AM
About abstract class and abstract method Sameer Java 4 08-31-2005 12:59 AM
Templates templates templates JKop C++ 3 07-21-2004 11:44 AM
Abstract Classes w/o abstract methods DaKoadMunky Java 4 04-20-2004 04:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57