Sunday, 15 September 2013

c++ - Access "this" pointer of concrete class from interface -


After writing a test, I have determined that this is not equivalent to an indicator in an interface Is this indicator of concrete class, which means that I can not just use the C-style on it.

  class abstractbase {...}; Class Interface {public: interface () {...} // now need abstractBase * virtual interface () {...} // and here}; Class Concrete: Public Abstraces, Public Enterprises {};  

My interface requires a base class pointers in the concrete square, which inherits it in the constructor and the district for registration and appropriation related to the interface.

Every concrete object interface first requires the inheritance of the intangible base class, it always happens in the layout first.

This is not difficult for the constructor, I can add a pointer to the interface constructor and pass from the concrete square . But the destroyer does not have any criteria, so I am in the darkness.

I have come up with a solution so far:

1 - The interface used in the Destructor Store in Pointer - adds a pointer to the light of memory overhead

  class AnInterface {public: AnInterface (AbstractBase * AP) {...} ~ Virtual Interface () {. ..} // and private here: Sarabasez * APTR; }; ... Concrete (): Interface (it) {}  

2 - Create an abstract method in the interface and apply it to the return in the concrete square - Adds to the overhead of impersonation for virtual calls

  class uninterface {virtual abbasebase * getPtr () = 0; }; Class Concrete: Public Abachesbabs, Public Interface {Absshuschesh * getPtr () {Returned; }};  

3 - dynamic_code worse than

Is there any more effective way to achieve this?

But since you say that the interface is designed to work with the functionality provided in the base class, then decoding is probably not a good thing.

I mean that if the problem happens with many interfaces, which all get the base class.


No comments:

Post a Comment