title: Inheritance and Interfaces in C++
body: <p>I've been going round in circles for ages trying to implement inheritance correctly in C++, and Google isn't really helping. I have working Java code that I'm porting across to C++ which relies heavily on interfaces.</p>
  
  <p>I'm writing a test bed for some genetic algorithms so I need generic variables that allow any type of that class to be associated with them, allow the same functions to be carried out, regardless of the specific type. For example I need a 'crossover' type which allows any kind of crossover to be stored in the variable, and will allow the same set of crossover methods to be performed on it.</p>
  
  <p>I have created an interface with the pure virtual function "performCrossover". This is then inherited by the generic "crossover" class, which is then inherited by the individual crossover types.</p>
  
  <p>At the moment the linker complains I'm redefining "problem::performCrossover" which I am, but that's exactly what I need. I can get round this by making the function pure virtual in the generic crossover class, but then I cannot instantiate it, which again is exactly what I need.</p>
  
  <p>I have also tried changing it too "crossovername::performCrossover" but then I get 'inherited member is not allowed'. This is where I am now.</p>
  
  <p>My interface:</p>
  
  <pre><code>class crossoverinterface {
  public:
      virtual genome** performCrossover(genome* firstParent, genome* secondParent) = 0;
  };
  </code></pre>
  
  <p>The generic crossover type I need to be able to instantiate with any kind of crossover. </p>
  
  <pre><code>class crossover: public crossoverinterface{ 
  public:
      crossover() {};
      crossover(int genomeLength, int nObjectives);
      ~crossover();
  
      genome** preCrossover(genome* firstParent, genome* secondParent);
      virtual genome** performCrossover(genome* firstParent, genome* secondParent);
  
  private:
      genome** solution;
      int genomeLength;
      int nObjectives;
  };
  </code></pre>
  
  <p>Example of a sub class 1:</p>
  
  <pre><code>class simulatedbinarycrossover: public crossover {
  public:
      simulatedbinarycrossover(int genomeLength, int nObjectives, double lowerBound, double upperBound);
  };
  
  genome** simulatedbinarycrossover::performCrossover(genome* firstParent, genome* secondParent){
      ...code...
  }
  </code></pre>
  
  <p>And finally the error: "performCrossover' : member function not declared in 'simulatedbinarycrossover'" Intellisense calls it 'inherited member is not allowed'.</p>
  
  <p>Hopefully I made some sense, it's a really arkward problem to try and describe.</p>
  
  <p>All suggestions welcome.</p>