title: overriding function for each instance c++
body: <p>So, what i'm trying to do is this:
  I would like to create a general class <code>MyCLASS</code> with a function <code>genericFunction()</code> which is empty by default. Now, when a co-worker wants to use this generic function, what he does is creating an instance of <code>MyClass</code>, and overriding <code>genericFunction()</code>, so it should give a resoult similar to this:</p>
  
  <pre><code>class MyClass{
     public:
        void genericFunction(){
           //boring default actions
        }
        //constructor
        MyClass(){
           //do things
        }
  };
  
  
  int main(){
     MyClass instance();
     //now we override the function, something like:
     instance.genericFunction(){
        cout &lt;&lt; "This new code exists only for this instance, and has been created outside the class!";
     } 
     instance.genericFunction();
  
     return 0;
  }
  </code></pre>
  
  <p>So that's basically what I would like to do.</p>
  
  <p>In the case that it is not possible, how can i make my class run a function that is going to be later defined in <code>main()</code>?</p>
  
  <p>Thanks a lot!</p>
  
  <p><strong>EDIT:</strong> To answer your questions:</p>
  
  <p>*I'm new to c++ and it's true that my background is from other languages
  *The idea is the following: You are creating objects that have a position, and if the position is in a certain range, <code>genericFunction()</code> is executed. The thing is that for each instance the function that is executed may (or in fact should) be different. The idea is 'inspired' by android's clickListener, where each element has a different function to execute when clicked</p>
  
  <p>Thanks again!</p>