Connecting Tech Pros Worldwide Help | Site Map

"Inheriting" during template specialisation

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 26th, 2007, 05:15 AM
Adam Nielsen
Guest
 
Posts: n/a
Default "Inheriting" during template specialisation

Hi again,

I've got another question about template specialisation. I would like
to declare some data types in the main template (the "base class") but I
would then like to extend the behaviour with template specialisations.
Unfortunately it seems that when I try this, the specialisation doesn't
get appended to the base template (as happens when you inherit from a
base class), but rather it replaces it completely, for example this code
won't compile:

template <typename T>
class A
{
public:
typedef std::vector<TV;
//V myVector; // works
};

class A<int>
{
private:
V intVector; // doesn't work
};


I get this error:

'V' is used as a type, but is not defined as a type.

Which implies that the typedef is getting lost. Is there a way around
this? Some sort of class inheritance would probably work, but I'd like
to try avoiding this as it's more for code clarity than anything else
('int' in my example above is actually a complex template instantiation,
so the code can become difficult to read if it's written out in full all
over the place.)

Thanks,
Adam.

  #2  
Old September 27th, 2007, 12:15 AM
Adam Nielsen
Guest
 
Posts: n/a
Default Re: "Inheriting" during template specialisation

IMHO you have to inherit to maximize code reuse. Cannot think of any
Quote:
other way...
Fair enough, that makes sense - thanks for your reply!

Cheers,
Adam.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.