Regarding iterator list giving invalid data after type casted from one pointer object type to another pointer object type

24 views Asked by At

I am trying to get data from iterator list which is pointing to a list of pointer object of A type. And this data is assigning to pointer object of B type.

Code:

   A* a=new A();
   B* b=new B();
   std::list<A*>a_list;
   for(std::list<A*> iterator it = a_list.begin(); it != a_list.end(); it++) {
          b= (B*)(*it); }

In this, i am getting correct value in (*it), but after above type conversion, most of the data is invalid. It is giving some random garbage value.

I have tried the type conversion of interpret_cast, but still it is giving me the same invalid data.

0

There are 0 answers