This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: template parameters cannot be friends
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: naje <najeiv at ukr dot net>, gcc-help at gcc dot gnu dot org
- Date: Fri, 21 May 2004 10:03:37 -0500
- Subject: Re: template parameters cannot be friends
- References: <E1BRA2G-000DsA-00@hammer.ukr.net>
Hi Naje,
With static polymorphism, I believe you should approach the problem this way:
- - - - - - - - - - - - -
#include <iostream>
class RadioButton
{
public:
void Draw() const
{
std::cout<<"radio button"<<std::endl;
}
};
class TextButton
{
public:
void Draw() const
{
std::cout<<"text button"<<std::endl;
}
};
template<typename T>
void Draw(T const& t)
{
t.Draw();
}
int main()
{
RadioButton rb;
Draw(rb);
TextButton tb;
Draw(tb);
}
- - - - - - - - - - - - -
You cannot have heterogenous collections of static polymorphic objects.
If you need a heterogenous collection of polymorphic objects, you need
dynamic polymorphism. (And, if so, I recommend using interface classes ...
classes consisting of nothing but pure virtual methods. I recommend
interface classes as a rule-of-thumb.)
HTH,
--Eljay