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 6 2597
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?
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/
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.
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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff |
last post by:
/* --------------------------------------------------------------------------
Hello,
I was experimenting with class templates and specializing member
functions and came across a simple problem...
|
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...
|
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...
|
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...
|
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...
|
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 {
|
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...
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |