473,686 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

partial template class

Hi NG,

Is it possible to make a template class, which has only one method that
makes use of the template type. The rest of the methods will work on the
base class of which the template type should always be derived.
I want the template to have a compile-time check of the type, but I
don't want a "full" template class because all generic methods will be
generated for every type I use this class with, which is a waste of
resources.

Thanks in advance,
Mark
--
<<Remove the del for email>>
Jul 22 '05 #1
2 1422

"Capstar" <ne**@deleg.hom eip.net> wrote in message
news:cl******** **@news.tudelft .nl...
Hi NG,

Is it possible to make a template class, which has only one method that
makes use of the template type. The rest of the methods will work on the
base class of which the template type should always be derived.
I want the template to have a compile-time check of the type, but I
don't want a "full" template class because all generic methods will be
generated for every type I use this class with, which is a waste of
resources.

Thanks in advance,
Mark
--
<<Remove the del for email>>


Its possible to make a template of one method only in an otherwise
non-template class

class X
{
template <class T>
void f(T t);

void g();
void h();
};

Its possible to derive a template class from a non-template base class and
put all the non-templated stuff there.

class XBase
{
void g();
void h();
};

template <class T>
class X : public XBase
{
void f(T t);
};

You're asking for one of those two possibilities I think, I'm not sure which
one so I mentioned both.

john
Jul 22 '05 #2
John Harrison wrote:
"Capstar" <ne**@deleg.hom eip.net> wrote in message
news:cl******** **@news.tudelft .nl...
Hi NG,

Is it possible to make a template class, which has only one method that
makes use of the template type. The rest of the methods will work on the
base class of which the template type should always be derived.
I want the template to have a compile-time check of the type, but I
don't want a "full" template class because all generic methods will be
generated for every type I use this class with, which is a waste of
resources.

Thanks in advance,
Mark
--
<<Remove the del for email>>

Its possible to make a template of one method only in an otherwise
non-template class

class X
{
template <class T>
void f(T t);

void g();
void h();
};


I thought so, but than I can call method f with any kind of type, and as
long as a conversion can be made to the type the rest of the methods
would use, it is OK. So that's not realy what I want since I can't force
a specific type that way.

Its possible to derive a template class from a non-template base class and
put all the non-templated stuff there.

class XBase
{
void g();
void h();
};

template <class T>
class X : public XBase
{
void f(T t);
};
I think this is what I need. If I use X<int> I can only call f with type
int, which is exactly what I want.

You're asking for one of those two possibilities I think, I'm not sure which
one so I mentioned both.

john


Thanks for your quick reply.
Mark
--
<<Remove the del for email>>
Jul 22 '05 #3

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

Similar topics

17
6854
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section 18.3.1, 'Iseq'). I want the version for containers that he gives, but also to provide a specialization for construction from a pair<It,It> (eg because that is returned by equal_range()).
9
2543
by: Philip Lawatsch | last post by:
Hi I'd like to implement some kind if type traits myself, but I have to support broken compilers (like visual studio) that do not support Partial Specialization. My first shot was something like this: ----8<--- typedef char IsPODForListArrayTrue;
8
7680
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I specialize Music<Bach>, I expect that the original play() method is available in the specialization, but it is not. How can I fix this? -X
7
2126
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
5
6581
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
6
2805
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on type parameters - in place of a template argument one can construct arbitrary valid C++ type declaration, more or less like in "typedef" statement. What about nontype parameters? Am I right that you cannot partially
6
2762
by: wkaras | last post by:
I tried a couple of compilers, and both gave errors compiling this: template <bool fin, typename T> T foo(T val); template <typename T> T foo<true, T>(T val) { return(val); } But both gave no errors compiling this:
9
2773
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second assign() function really a specialization of the first assign() or is it an assign() overload? Thank you. -- Marek
10
2785
by: jason.cipriani | last post by:
I never seem to be able to get this right. Here I have some code: template <typename T, int Nclass A { void f (T); }; template <typename Tvoid A<T,1>::f (T) { } template <typename Tvoid A<T,3>::f (T) {
1
2223
by: Ioannis Gyftos | last post by:
Hello, First the code :) /////////////////////////////////////////////////////////////////////////////////// // in another header file namespace LJC{
0
8585
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8933
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8770
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6440
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5799
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2947
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.