473,395 Members | 1,666 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.

Inheriting a template class

5
Ok, quick question. I want to create a base class really just to use in a polymorphic vector, but since there will be generic stuff in there I want there to be a bit of functionality. Now, there's going to be a pointer in there, but depending on the inherited class, the type of pointer could change. I was wondering if it was possible to make the base class a template class, and specify the template when I inherit. If that makes no sense, see below. I would just code it out, but I'm in the middle of planning some other stuff and I don't want to get into coding it if it won't even work.

Does the below make sense?

Expand|Select|Wrap|Line Numbers
  1.  
  2. template <class T>
  3. class CBase
  4. {
  5.     T* m_pointer;
  6.     CBase();
  7.     ~CBase();
  8. }
  9.  
  10. class CProcessInfo : CBase<CProcess>
  11. {
  12.     etc...
  13. }
  14.  
  15.  
Jan 14 '07 #1
3 1588
Banfa
9,065 Expert Mod 8TB
I think that should work.
Jan 14 '07 #2
Shakje
5
Just to clarify, the code has to be extra readable, I guess I could just use a void* and overload it as necessary I just thought this might be a bit more elegant if it works. Another related question, if I have say:

Expand|Select|Wrap|Line Numbers
  1.  
  2. enum TYPE {  PT_NULL,
  3.                       PT_PROCESS,
  4.                       PT_VARIABLE,
  5.                       etc };
  6.  
  7. static const TYPE m_type = PT_NULL;
  8.  
  9.  
When I inherit the class can I redefine m_type?

As you can guess my inheritance logic is a bit shady, I've been doing Java in a course for the last year and just getting back into my C++ :)
Jan 14 '07 #3
Shakje
5
Never mind, just being silly, if I initialise it in the constructor it should all be fine.

If it comes down to it, I'll just have it as a private static with a getter only.

Thanks for the reply banfa :)
Jan 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: jarradw | last post by:
I am trying to figure out if this will work. I have a template base class that I want to be able to inherit from, the classes that will need to inherit from this also need to be tamplates. Is this...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
7
by: Amu | last post by:
Hi i am stuck up in a part of project where i have to inherit the VC++ template classes into C#.net. Please provide me the solution for this .
3
by: l.s.rockfan | last post by:
Hello, how do i have to call an inherited, templated class constructor from the initializer list of the inheriting, non-templated class constructor? example code: template<typename T>...
4
by: l.s.rockfan | last post by:
Hello, how do i have to call an inherited, templated class constructor from the initializer list of the inheriting, non-templated class constructor? example code: template<typename T>...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.