473,618 Members | 3,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about class specialization in templates

I am frustrated by class specialization. i don't
think it helps me a lot.

suppose we have

template <class T>
class Talkative
{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();

template <>
class Talkative<Dog>
{

}

then in the declaration of
template <> class Talkative<Dog>, i need to re-write
everthing(code) that are already in the templates.
from constructor, destructor, copy-structor,
sing(), class variables t.

what a pity? is there any way to avoid this?
i was so frustrated by this issue!

(class member specialization doesn't fit here, since
i need to add a new function bark(); )

If you have good thoughts, could you please share with me.
thanks!
jesse

Jul 19 '05 #1
6 2631
jesse wrote:
I am frustrated by class specialization. i don't
think it helps me a lot.

suppose we have

template <class T>
class Talkative
{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();

template <>
class Talkative<Dog>
{

}

then in the declaration of
template <> class Talkative<Dog>, i need to re-write
everthing(code) that are already in the templates.
from constructor, destructor, copy-structor,
sing(), class variables t.

what a pity? is there any way to avoid this?
i was so frustrated by this issue!

(class member specialization doesn't fit here, since
i need to add a new function bark(); )

If you have good thoughts, could you please share with me.
thanks!
jesse

class x:public Talkative<ass>
{
/*constructors*/
void bark() {/*whatever*/}
void sing() {Talkative::sin g()}
}

why do you need specialization?

Jul 19 '05 #2
jesse wrote in news:3F******** ****@yahoo.com:
I am frustrated by class specialization. i don't
think it helps me a lot.

suppose we have

template <class T>
class Talkative
class Talkative_base
{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();

template < typename T >
class Talkative: public Talkative_base< T >
{
};

template <>
class Talkative<Dog>

class Talkative<Dog> : public Talkative_base< Dog >
{

}

then in the declaration of
template <> class Talkative<Dog>, i need to re-write
everthing(code) that are already in the templates.
from constructor, destructor, copy-structor,
sing(), class variables t.

what a pity? is there any way to avoid this?
i was so frustrated by this issue!

(class member specialization doesn't fit here, since
i need to add a new function bark(); )

If you have good thoughts, could you please share with me.
thanks!


Don't mix specialization and inheritance, they are not (and AFAIKT
were never meant to be) the same thing.

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3
In article <3F************ @yahoo.com>, je*****@yahoo.c om says...

[ ... ]
//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();


Specialization gives specialization, not inheritance. If you want
inheritance, that's what you should use.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4
Rob & all:

thanks for your all advice.

That is the key point: I tried to mix specialization and inheritance.
it is impossible to do it in one step. it has to be done in two steps,

jesse



Rob Williscroft wrote:
jesse wrote in news:3F******** ****@yahoo.com:

I am frustrated by class specialization. i don't
think it helps me a lot.

suppose we have

template <class T>
class Talkative

class Talkative_base

{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();

template < typename T >
class Talkative: public Talkative_base< T >
{
};
template <>
class Talkative<Dog>


class Talkative<Dog> : public Talkative_base< Dog >

{

}

then in the declaration of
template <> class Talkative<Dog>, i need to re-write
everthing(cod e) that are already in the templates.
from constructor, destructor, copy-structor,
sing(), class variables t.

what a pity? is there any way to avoid this?
i was so frustrated by this issue!

(class member specialization doesn't fit here, since
i need to add a new function bark(); )

If you have good thoughts, could you please share with me.
thanks!

Don't mix specialization and inheritance, they are not (and AFAIKT
were never meant to be) the same thing.

HTH

Rob.


Jul 19 '05 #5
Rob & all:

thanks for your all advice.

That is the key point: I tried to mix specialization and inheritance.
it is impossible to do it in one step. it has to be done in two steps,

jesse
Rob Williscroft wrote:
jesse wrote in news:3F******** ****@yahoo.com:

I am frustrated by class specialization. i don't
think it helps me a lot.

suppose we have

template <class T>
class Talkative

class Talkative_base

{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();

template < typename T >
class Talkative: public Talkative_base< T >
{
};
template <>
class Talkative<Dog>


class Talkative<Dog> : public Talkative_base< Dog >

{

}

then in the declaration of
template <> class Talkative<Dog>, i need to re-write
everthing(cod e) that are already in the templates.
from constructor, destructor, copy-structor,
sing(), class variables t.

what a pity? is there any way to avoid this?
i was so frustrated by this issue!

(class member specialization doesn't fit here, since
i need to add a new function bark(); )

If you have good thoughts, could you please share with me.
thanks!

Don't mix specialization and inheritance, they are not (and AFAIKT
were never meant to be) the same thing.

HTH

Rob.


Jul 19 '05 #6
Rob and all:

thanks for yor all advice. the point here is i tried to mix
inheritance and specialization.

It has to be done in two steps, not in one step. as Ron suggested.
the only overhead is that i need to rewrite constructor.

In com.lang.c++.mo derate newsgroup, Aaron Bentley comes with another
good idea:

template <class T, int specialize=true >
class Talkative
{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

template <> class Talkative<Dog, true>: public Talkative<Dog, false>
{
public:
bark() {}
};

this idea also needs rewrite constructor.
jesse
Rob Williscroft wrote:
jesse wrote in news:3F******** ****@yahoo.com:

I am frustrated by class specialization. i don't
think it helps me a lot.

suppose we have

template <class T>
class Talkative

class Talkative_base

{
T& t;
public:
Talkative( T& obj ) :
t( obj ) {
};
~Talkative(){};

void talk(){t.talk() ;};
void sing(){t.sing() ;};
void whisper(){t.whi sper();};
};

//through class specialization , i want:
// 1) inherit the sing() from the base template class;
// 2) specialization the talk();
// 3) and add a new function bark();

template < typename T >
class Talkative: public Talkative_base< T >
{
};
template <>
class Talkative<Dog>


class Talkative<Dog> : public Talkative_base< Dog >

{

}

then in the declaration of
template <> class Talkative<Dog>, i need to re-write
everthing(cod e) that are already in the templates.
from constructor, destructor, copy-structor,
sing(), class variables t.

what a pity? is there any way to avoid this?
i was so frustrated by this issue!

(class member specialization doesn't fit here, since
i need to add a new function bark(); )

If you have good thoughts, could you please share with me.
thanks!

Don't mix specialization and inheritance, they are not (and AFAIKT
were never meant to be) the same thing.

HTH

Rob.


Jul 19 '05 #7

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

Similar topics

2
5770
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem which I can't figure out. I have a simple class C with 2 template member objects, and a function print() that prints the value of these objects. I defined a specialization of print() for C<string, char> which is called correctly. Then I wanted...
4
2576
by: SainTiss | last post by:
Hi, From what I've read in several places, it seems that explicit specialization of member functions of class templates is allowed, but partial specialization isn't: template<class T, class R> class A { void foo(); }
1
1643
by: SainTiss | last post by:
Hi, I've been looking into the standard for a clear statement on whether partial specialization of member functions of class templates is allowed or not. 14.7.3/4 says that explicit specialization of a member function is legal, but doesn't state that partial specialization is not. One might argue that the standard indicates that partial specialization implies a distinct template, and therefore defining a member function
1
2263
by: Alfonso Morra | last post by:
if I have a class template declared as ff: (BTW is this a partial specialization? - I think it is) template <typename T1, myenum_1 e1=OK, my_enum_2=NONE> class A { public: A(); virtual ~A() ;
6
2760
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:
4
3320
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class foo {
75
5419
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has been a significant decline in the number of students opting to take courses in C++. I just want to let people know what I believe are the biggest obstacles to C++ language acquisition, and what aspects of the language make it less appealing than...
7
2552
by: (2b|!2b)==? | last post by:
I have a class template. Each of the instantiations implements a method in the class template differently, so I (need?) to use template speciaization. My question is this, when writing the specialization, do I need to implement only the method that is 'different', or do I need to implement all the methods in the class template? template <typename T1, typename T2>
2
1709
by: zeeshan708 | last post by:
I am quoting this from Deitel's 5th edition on C++ Now the question is... Why is there a separate specialization for char data type ??? Is it because the files normally are made up of characters and have nothing to do with ints and floats etc etc. Are there specializations for other data types as well or is it just for character data type only? Detailed answers and links shall be appreciated alot. Regards.
0
8153
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
7126
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6101
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
5552
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
4065
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2587
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
1
1760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1459
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.