This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33762] New: partial template specialization question
- From: "gzljg at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Oct 2007 18:57:12 -0000
- Subject: [Bug c++/33762] New: partial template specialization question
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Probably this is not a bug, but just I want to make clear to myself...
I have a 'general' template class, and can specialize it for one class(say
base), can I then assume all other classes that derived from 'base' class are
using the specialized version template function(same as the base one)?
Example code:
#include <iostream>
using namespace std;
class Dummy{};
class Base {} ;
class Derive : virtual public Base{};
template <class T> class Stub : virtual public T
{
public:
Stub()
{
std::cout << "template <class T> class Stub : virtual public T"
<< std::endl;
}
};
template <> class Stub<Base>
{
public:
Stub()
{
std::cout << "template <> class Stub<Base> "
<< std::endl;
}
};
/*
I have to enable this to make it work as expected, but this is definitely not I
wants, since this mean I had to specialize _all_ the dervied classes like this,
which may be too much....
template <> class Stub<Derive>
{
public:
Stub()
{
std::cout << "template <> class Stub<Derive> "
<< std::endl;
}
};
*/
class A : public Stub<Dummy>
{
};
class B : public Stub<Base>
{
};
class C : public Stub<Derive>
{
};
int main()
{
A a; // expected, use the most general template.
B b; // expected, use the specialized template since T=Base
C c; // ?? I expected it will use the specialized template as well, since
T=Derive, which Derive is derived from Base. Am I wrong here??
return 0;
}
program output:
template <class T> class Stub : virtual public T
template <> class Stub<Base>
template <class T> class Stub : virtual public T // I expected should be "
template <> class Stub<Base>" as above here.
--
Summary: partial template specialization question
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gzljg at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33762