11

私はこの機能を持つクラスを持っています:

typedef boost::shared_ptr<PrimShapeBase> sp_PrimShapeBase; 



class Control{
     public:
         //other functions
         RenderVectors(SDL_Surface*destination, sp_PrimShapeBase);
     private:
         //other vars
          vector<sp_PrimShapeBase> LineVector;

};

//the problem of the program

void Control::RenderVectors(SDL_Surface*destination, sp_PrimShapeBase){
    vector<sp_PrimShapeBase>::iterator i;

    //iterate through the vector
    for(i = LineVector.begin(); i != LineVector.end(); i ++ ){
      //access a certain function of the class PrimShapeBase through the smart
      //pointers
      (i)->RenderShape(destination); 

    }
}

コンパイラは、クラスboost :: shared_ptrには「RenderShape」というメンバーがないことを教えてくれます。これは、クラスPrimShapeBaseが確かにその機能を持っていますが、別のヘッダーファイルにあるためです。これの原因は何ですか?

4

2 に答える 2

20

意味ない

(*i)->RenderShape(destination); 

iはイテレータ、*ishared_ptr(*i)::operator->()はオブジェクトです。

于 2012-08-14T20:59:25.447 に答える
7

それiはイテレータだからです。一度逆参照するとスマートポインタが得られるので、二重逆参照する必要があります。

(**i).RenderShape(destination);

また

(*i)->RenderShape(destination); 
于 2012-08-14T21:00:48.537 に答える