abstract - How to "hide" a virtual method? (C++) -


There is a post with a very similar title, but as I had understood the actual problem is different.

I would like to know that if a user is written to override a certain method, but at the same time it is not possible to call this method (but it is only from within my class) .

For example, if I want to do the following:

  class AbstrDataSource {Private: int index; Protected: Int present data; Public: int getData () {currentData;} zero load data (int i) {// check index here (index! = I) {doLoad (i);} this-> gt; Index = i; } Virtual Zero doLoad (int i) = 0; }; In the load data () I can see that the index is in a valid range and some bookkeeping is done, whereas actual loading is to be provided by the user by override (). Because pure virtual methods are part of the interface, they are public, but how can I implement the implementation of doLoad () to see only my own class?  

Class DataSupplier {Public: DataSpplier (Abstraadosource * S): Source (S) Zero Load Data (Int.) {Source-> loadData (i);} int getData ()) {Return source-> GetData ();} Private: AbstrDataSource * Source; };

Instead of using abstract class, I use the cover:

  int SomeCalculation (DataSupplier * a, DataSupplier * b) {return a -> GetData () + B-> GetData (); }  

However, it does not really help. Say that a second person provides the implementation of my abstract class:

  class ImplDataSource: public AbstrDataSource {public: zero doLoad (int i) {this- & gt; CurrentData = i;}};  

Then the third person still has access to doLoad ():

  void main () {AbstrDataSource * ads = new ImplDataSource (); DataSpplier * ds1 = New Data Viewer (Advertising); Datatyplier * DS2 = New Dataplayer (Advertising); Advertising-> DoLoad (10); // & lt; - How to avoid it ?? Ds1-> LoadData (12); Ds2-> LoadData (12); SomeCalculations (DS1, DS2); }  

Perhaps there is a way to get it using the Access specifier ...?

EDIT: I have found some useful answers, but I feel that I did not tell my question clearly until ImplDataSource declares the doLoad () as protected or private. All right However, appearing only on the abstraredosource, there is no indication that any implementation of doLoad () should be private (even if the intangible loads are protected or private, no access to actual implementation). I would like to know whether it is possible to "apply" any implementation of the abstract doLoad () in any way to private, that I am just thinking a very complex and intangible method ("personally implementing Or may be unsuccessful ") is the easiest way to add a comment.

secure method doLoad (), then it can only be called from within the superclass, And this is the pure virtual method of the base class (and hiding) surcharges.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -