Cannot compile with Boost Libraries

Help
daguldagul
2007-10-17
2013-05-14
  • daguldagul
    daguldagul
    2007-10-17

    Class Base
    {  Base::get(); };
    Class Child inherits Class Base
    {};

    In main()...

    std::vector< boost::shared_ptr<Child> >::iterator iSessionIter;
    std::vector< boost::shared_ptr<Child> > aoSessions;

    ....
    aoSessions.push_back( boost::shared_ptr<Child>( new Child( name1, name2 ) ) );
    ....

    for( iSessionIter = aoSessions.begin(); iSessionIter != aoSessions.end(); iSessionIter++ )
    {
        ( (boost::shared_ptr<Base>)(*iSessionIter) )->get();
    }

    Error:
    boost_1_34_0/boost/shared_ptr.hpp", line 194: Error: Cannot use Child * const to initialize Base*.

    Please help how to fix this compilation error. Is this a boost library problem?
    Thank you so much!

     
    • daguldagul
      daguldagul
      2007-10-17

      WITH CORRECTION:

      Class A
      {
      public:
        get();
      };

      Class A_Wrapper
      {
         A oA;
      };

      In main()...

      std::vector< boost::shared_ptr<A_Wrapper> >::iterator iSessionIter;
      std::vector< boost::shared_ptr<A_Wrapper> > aoSessions;

      ....
      aoSessions.push_back( boost::shared_ptr<A_Wrapper>( new A_Wrapper( name1, name2 ) ) );
      ....

      for( iSessionIter = aoSessions.begin(); iSessionIter != aoSessions.end(); iSessionIter++ )
      {
      ( (boost::shared_ptr<A>)(*iSessionIter) )->get();
      }

      Error:
      boost_1_34_0/boost/shared_ptr.hpp", line 194: Error: Cannot use A_Wrapper* const to initialize Base*.

      Please help how to fix this compilation error. Is this a boost library problem?
      Thank you so much!

       
    • daguldagul
      daguldagul
      2007-10-17

      WITH CORRECTION:

      Class A 

      public:
      get(); 
      }; 

      Class A_Wrapper
      {
      A oA;
      }; 

      In main()... 

      std::vector< boost::shared_ptr<A_Wrapper> >::iterator iSessionIter; 
      std::vector< boost::shared_ptr<A_Wrapper> > aoSessions; 

      .... 
      aoSessions.push_back( boost::shared_ptr<A_Wrapper>( new A_Wrapper( name1, name2 ) ) ); 
      .... 

      for( iSessionIter = aoSessions.begin(); iSessionIter != aoSessions.end(); iSessionIter++ ) 

      ( (boost::shared_ptr<A>)(*iSessionIter) )->get(); 

      Error: 
      boost_1_34_0/boost/shared_ptr.hpp", line 194: Error: Cannot use A_Wrapper* const to initialize A*. 

      Please help how to fix this compilation error. Is this a boost library problem? 
      Thank you so much!