title: Fixing C++ Multiple Inheritance Ambiguous Call
body: <p>I have three classes structured like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Keyword
  {
      public:
          virtual float GetValue() = 0;
  };
  
  class CharacterKeyword : public Keyword
  {
      public:
          virtual float GetValue(){return _value;}
      private:
          float _value;
  };
  
  class MeasurementKeyword : public Keyword
  {
      public:
          virtual float GetValue(){return _value;}
      private:
          float _value;
  };
  
  class AddressType : public CharacterKeyword, public MeasurementKeyword
  {
  
      private:
          float address;
          float addresExt;
  };
  
  int main()
  {
      AddressType *a = new AddressType();
      a-&gt;GetValue();
      return 0;
  }
  </code></pre>
  
  <p>I am getting the following: <br /><br />
  <code>In function ‘int main()’:</code><br />
  <code>error: request for member ‘GetValue’ is ambiguous</code><br />
  <code>error: candidates are: virtual float Keyword::GetValue()</code><br />
  <code>error: virtual float MeasurementKeyword::GetValue()</code><br />
  <code>error: virtual float CharacterKeyword::GetValue()</code><br /></p>
  
  <p>I have done some reading into multiple inheritance and I know that it has a lot of pitfalls - this being one of them. I need my class structure to be like this so I was wondering if there was a way that I could fix this using templates? </p>
  
  <p><strong>Update</strong> <br />
  After reading your comments, my original thought was that maybe I can just delineate between an <code>AddressType</code> that is a <code>CharacterKeyword</code> and an <code>AddressType</code> that is a <code>MeasurementKeyword</code> by templating the <code>AddressType</code>. And using it as such in the updated code. <strong>OR</strong> I can just specify the namespace of the member that I would like. Since the templated way has not been mentioned yet as an answer, is it a bad fix? Should I just specify the namespace of the member I want?</p>
  
  <pre><code>template &lt;class T&gt;
  class AddressType : public T
  {
  
      private:
          float address;
          float addresExt;
  };
  
  int main()
  {
      AddressType&lt;MeasurementKeyword&gt; *a = new AddressType&lt;MeasurementKeyword&gt;();
      a-&gt;GetValue();
      return 0;
  }
  </code></pre>