C++ Iterating through a vector of smart pointers

前端 未结 2 1148
别那么骄傲
别那么骄傲 2021-02-08 07:50

i have a class that has this function:

typedef boost::shared_ptr sp_PrimShapeBase; 



class Control{
     public:
         //other function         


        
相关标签:
2条回答
  • 2021-02-08 08:07

    Don't you mean

    (*i)->RenderShape(destination); 
    

    ?

    i is the iterator, *i is the shared_ptr, (*i)::operator->() is the object.

    0 讨论(0)
  • 2021-02-08 08:13

    That's because i is an iterator. Dereferencing it once gives you the smart pointer, you need to double dereference it.

    (**i).RenderShape(destination);
    

    or

    (*i)->RenderShape(destination); 
    
    0 讨论(0)
提交回复
热议问题