Re: Polymorphism without virtual in C++
feel wrote:
2 Polymorphism in this design is the Impl pointer in root class. we
can implementation the real version class for every leaf class.
Your base class actually looks simply like a (well, some kind of)
smart pointer.
Yet I still fail to see where the polymorphism is, unless your base
class smart pointer is pointing to different class type, which can be
derived and have virtual functions. If it doesn't, then it's simply a
smart pointer which points to some numeric data, and that's it.
I don't believe the definition of "polymorphism" is "each object can
have differing data". If that was the case, then std::string would be
polymorphic because different instances of std::string can have
differing data (eg. different string length and contents).
In fact, I think std::string is a good comparison point. What are the
relevant differences between your classes and std::string (other than
std::string doesn't expose its private data in its protected section)?
Why? because I donot want a big class in my header file.
Is it simply a question of style? You don't want all the private data
of the class to be viewable from the header file?