title: no viable conversion from 'shared_ptr<src::IdInterface>' to 'shared_ptr<IdInterface>'
body: <p>I am trying to understand an error I see when attempting to  implement the Visitor pattern for validation purpose.  When i execute cmake ../ from the build directory i am getting the following  error: </p>
  
  <pre><code>validator/src/Id.cpp:30:38: error: no viable conversion from 'shared_ptr&lt;src::IdInterface&gt;' to 'shared_ptr&lt;IdInterface&gt;'
                  bool isValid = validator-&gt;isValid( castedObj );
  
  /home/tito/Projects/validator/src/IdValidatorInterface.h:24:50: note: passing argument to parameter 'entity' here
                   virtual bool isValid( shared_ptr&lt;IdInterface&gt; entity )  = 0;
  </code></pre>
  
  <p>I have been able to replicate the error with simple 3 classes For the sake of the example i have put them in the same namespace. 
  Those classes are "Id" class this is the element i would like to validate. The Id inherits from BasePrimitive. The sole purpose of BasePrimitive class is to be able to get a share pointer validating entity since the BasePrimitive class inherits from<br>
  "enable_shared_from_this".  i.e. the code below</p>
  
  <pre><code>#include "Id.h"
  #include "IdInterface.h"
  #include "IdValidatorInterface.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  namespace src
      {
  
      const string Id::name = "ID";
  
      Id::Id()
          {
          }
  
      Id::~Id()
          {
          }
  
      bool Id::validate(shared_ptr&lt;IdValidatorInterface&gt; validator)
      {
  
          shared_ptr&lt;Id&gt; thisObj = shared_from_this();
          shared_ptr&lt;IdInterface&gt; castedObj = static_pointer_cast&lt;IdInterface&gt;(thisObj);
  
  
  
          bool isValid = validator-&gt;isValid( castedObj );
          if (!isValid)
              {
  
              vector&lt;string&gt; vectorOfErrors = validator-&gt;validate(castedObj );
  
              std::cout &lt;&lt; " the Id has NOT been validated" &lt;&lt; std::endl;
              } else
                  {
              std::cout &lt;&lt; " the Id has been validated" &lt;&lt; std::endl;
  
          }
  
          return isValid;
          }
  
  
      string Id::getName() const {
          return Id::name;
          }
  
  
      }
  </code></pre>
  
  <p>the part where the code is broken is this one: Here i get a share_ptr from this class and then do a static pointer case. This works well but when i try to pass it to the isValid method then it breaks.</p>
  
  <pre><code>shared_ptr&lt;Id&gt; thisObj = shared_from_this();
  shared_ptr&lt;IdInterface&gt; castedObj = static_pointer_cast&lt;IdInterface&gt;(thisObj);
  
  bool isValid = validator-&gt;isValid( castedObj );
  </code></pre>
  
  <p>and the BasePrimitive class </p>
  
  <pre><code>namespace src {
  
  class BasePrimitive: public enable_shared_from_this&lt;BasePrimitive&gt; {
  
  public:
      ~BasePrimitive();
      BasePrimitive();
  
  };
  
  }
  </code></pre>
  
  <p>Then i have my validator class i.e. IdValidator</p>
  
  <pre><code>#include "IdValidator.h"
  #include "Id.h"
  #include "IdInterface.h"
  
  using namespace std;
  
  namespace src
      {
  
      using Id = src::Id;
  
      IdValidator::IdValidator()
          {
          }
  
      bool IdValidator::isValid(shared_ptr&lt;IdInterface&gt; entity)
          {
  
          vector&lt;string&gt; listOfErros = validate(entity);
  
          if(listOfErros.empty() ){
              return false;
          }else{
              return true;
          }
  
          }
  
      vector&lt;string&gt; IdValidator::validate(shared_ptr&lt;IdInterface&gt; entity)
          {
  
  
          vector&lt;string&gt; stringList = vector&lt;string&gt;();
  
          // do some validation of the name
          string name = entity-&gt;getName()
  
          if (name == "BadName")
              {
              string error = "Error. id name is bad";
              stringList.push_back(error);
              return stringList;
              }
  
          return stringList;
  
          }
      }
  </code></pre>
  
  <p>And i do have 3 other interfaces i.e. BaseElementValidatorInterface, IdValidatableInterface, IdValidatorInterface which are there simply for explicit in order to state that those a pure virtual functions.</p>
  
  <p>in the last interface i.e. IdValidatorInterface i am using a forward declare to the IdInterface in order to avoid cyclic includes.  </p>
  
  <p>i.e. </p>
  
  <pre><code>class IdInterface;
  </code></pre>
  
  <p>The first probelm: 
  "no viable conversion from 'shared_ptr' to 'shared_ptr'"</p>
  
  <p>the only difference here i see is the full qualified namespace. I would like to understand the nature i.e. the origin of this error. Is this something related to the compiled definitions I pass to clang i.e.</p>
  
  <pre><code>add_definitions(" -pedantic -pedantic-errors -W ")
  add_definitions(" -Wall -Wextra  -Werror -Wshadow -Wnon-virtual-dtor ")
  add_definitions(" -v ")
  </code></pre>
  
  <p>or something else.</p>
  
  <p>I have found multiple articles in stackoverflow about this but all of those were mainly about different types i.e. somethig like  bools and string.</p>
  
  <p>like this one 
  <a href="https://stackoverflow.com/questions/51595551/no-viable-conversion-from-int-to-time">no viable conversion from &#39;int&#39; to &#39;Time&#39;</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23417592/no-viable-conversion-from-bool-to-stdstring">No viable conversion from &#39;bool&#39; to &#39;std::string&#39;</a></p>
  
  <p>I  do understand  the articles mentioned above, but in my case the compiler is seeing the same type except the namespace is different i.e.'shared_ptr' to 'shared_ptr'  how to i tell the compiler that those are the same objects? Why is the compiler  seeing different namespaces when this is the same class i.e. "IdInterface". In some of the articles above it has been mentioned that this error can be seen if the class in not defined , but for this reason i use explicetelly the fotrward declaration. </p>
  
  <p>I have put those whole 3 classes and the 3 interfaces on github to show the complete picture. <a href="https://github.com/courteous/visitor/tree/master/src" rel="nofollow noreferrer">https://github.com/courteous/visitor/tree/master/src</a> </p>
  
  <p>Any help is highly appreciated</p>