I created an abstract abstract interface for the source for a later extension. But what if I want to expand derivative classes with some special methods? So I have the interface:
class virtualFoo {public: virtual ~ virtualfu () {} create virtual zero () = 0; Virtual Zero Start () = 0; }; and a derived class with an additional method:
class concreteFoo: public virtualfe {public: concreteFoo () {} ~ concreteFoo () {} Virtual Zero () {} Virtual Zero Initialize () {} void ownMethod () {}}; So I try to make an example of ConcreteFu and try to call myMethod like this:
< Code> void main () {virtualFoo * ptr = new concreteflu (); ConcreteFoo * PART2 = Dynamic_Cast & lt; ConcreteFoo * & gt; (PTR); If (cord! = PTR2) PTR-2-> Self-method (); } This works but is not really a great way if I type ptr-> OwnMethod (); then the compiler directly complains that this method is not part of virtualFoo . What is the chance to do this without using dynamic_cast ?
Thanks in advance!
This is what is meant for dynamic_cast . However, you can usually change your design to avoid using it. Since you give an abstract example, it is difficult to decide whether you should do it in a different way.
Comments
Post a Comment