title: C++ checking the type of reference
body: <p>Is it bad design to check if an object is of a particular type by having some sort of ID data member in it?</p>
  
  <pre><code>class A
  {
  
  private:
    bool isStub;
  public:
   A(bool isStubVal):isStub(isStubVal){}
   bool isStub(){return isStub;}
  
  
  };
  
  class A1:public A
  {
   public:
   A1():A(false){}
  };
  
  class AStub:public A
  {
   public:
   AStub():A(true){}
  };
  </code></pre>
  
  <p>EDIT 1:
   Problem is A holds a lot of virtual functions, which A1 doesn't override but the stub needs to, for indidicating that you are working on a stub instead of an actual object. Here maintainability is the question, for every function that i add to A, i need to override it in stub. forgetting it means dangerous behaviour as A's virtual function gets executed with stub's data. Sure I can add an abstract class ABase and let A and Astub inherit from them. But the design has become rigid enough to allow this refactor. 
      A reference holder to A is held in another class B. B is initialized with the stub reference, but later depending on some conditions, the reference holder in B is reinitialized with the A1,A2 etc.. So when i do this BObj.GetA(), i can check in GetA() if the refholder is holding a stub and then give an error in that case. Not doing that check means, i would have to override all functions of A in AStub with the appropriate error conditions.</p>