template parameters cannot be friends

naje najeiv@ukr.net
Fri May 21 15:26:00 GMT 2004


Hi, Eljay

>#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);
>}
  
but then, i can't make Draw for another superclass,
for example
template<typename T>
Draw(const Window<T>& w)
{
 // do nothing maybe
}

i do not need put method draw in Window's children.

> You cannot have heterogenous collections of static polymorphic objects.

but it's working in older versions of gcc, it's working in gcc 3.3.3 but i can't assert error in compile time, or maybe i don't understand meaning of world 'heterogenous'




More information about the Gcc-help mailing list