This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: template parameters cannot be friends


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'



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]