Re: template parameters cannot be friends

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux