Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3585

Re: Dynamically Call a Function

$
0
0

But why would anyone declare the method "of_process()" in both C and X?  That's a violation of basic OO principles.

 

The proper method would be to refactor the method declaration into class B (the common ancestor class), and then provide different implementation specifics in C and X.  In that case, this code snippet would compile AND execute perfectly at runtime.

 

b  b_ptr

 

b = create b_ptr

b_ptr.function DYNAMIC of_process()  // calls the empty B implementation

destroy b_ptr

 

b_ptr = create c_ptr  // downcast into a C class

b_ptr.function DYNAMIC of_process()  // calls the C implementation

destroy b_ptr

 

b_ptr = create x_ptr  // downcast into an X class

b_ptr.function DYNAMIC of_process()  // calls the X implementation

destroy b_ptr

 

-Paul-


Viewing all articles
Browse latest Browse all 3585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>