static_casting from Parent to Child??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux