473,396 Members | 1,935 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,396 software developers and data experts.

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.whisper();};
};

//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 2620
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.whisper();};
};

//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::sing()}
}

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.whisper();};
};

//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.com 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.whisper();};
};

//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.


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.whisper();};
};

//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.


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++.moderate 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.whisper();};
};

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.whisper();};
};

//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.


Jul 19 '05 #7

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

Similar topics

2
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem...
4
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...
1
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...
1
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...
6
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...
4
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
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...
7
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...
2
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...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.