This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

static_casting from Parent to Child??


In the bellow sample I get an error saying : cannot convert from 'std::shared_ptr<Parent>' to 'Child'
class Parent : public std::exception{
private:
   //....
public:
   void Display(){std::cout << what() << std::endl;}
};

class Child : public Parent{
void Display(){MessageBox(0,TEXT("good",TEXT("Menu"),MB_OK | MB_ICONERROR);}
};

class m_class1{
private:
   std::shared_ptr<Parent> ex;
public:
   m_class1(){ ex.reset(new Parent); }
   void foo(){
   //...
   throw ex;
   }
};

void main(){
  auto ex = std::shared_ptr<Child>();
  try{
   auto mc = std::shared_ptr<m_class1>();
   mc->foo();
       /// bla bla
  }catch(std::shared_ptr<Parent>& e){
   ex = static_cast<Child>(e); // Error

   //...
  }
}


What can I do to remove this error


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]