title: C++ cast operator of pointer
body: <p>I tried the following code sample but A* aa = c; does not compile. Why is the conversion operator not called? The same example without pointers works. So I do not know why C must inherit from A? Thanks for your help.</p>
  
  <p>EDIT: I know coding something like this makes no sense. But I just want to understand the conversion stuff.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class A {    
  public:
    int mValue = 0;
  };
  
  class B : public A{
  public:
    operator A*() { 
      return this;
    }
  };
  
  class C {
  public:
    operator A*() {
      return new A();
    }
  };
  
  int main(int argc, char* argv[])
  {
    B* b = new B();
    A* a = b;
  
    C* c = new C();
    A* aa = c;
  }
  </code></pre>