2011-11-08 17 views
4
Pickup::Pickup(std::vector<Agent, std::allocator<Agent>> &agents)" provides no initializer for: 

多くの私のコンストラクタでこのエラーが発生しています。私は初期化子を提供していないことを告げる直前に、間違いなくエラーが突然終了します。さらに、私は実際にそれを必要とするすべての初期化を提供していると確信しています。誰もこれにどのような光を当てることができますか?には.....の初期化子はありません。何?

#include "Pickup.h" 

    Pickup::Pickup(vector<Agent>& agents) 
     : GameObject(), TOLERANCE(0.1f) 
    { // this brace is underlined and is where the error occurs. 

     xRotation = D3DXVECTOR3(0.005f, 0.005f, 0.04f); 

     count = 0; 

     index = -1; 

     nodeIndex = -1; 

     isPresent = true; 
    } 

    void Pickup::Regenerate() 
    { 
     //when the pickup gets picked up, start a countdown 
     count++; 

     if (count == 300) 
     { 
      isPresent = true; 
      count = 0; 
     } 
    } 

    //void Pickup::addAmmo(int agentIndex) { } 

    void Pickup::Update() 
    { 
     Rotation(Rotation() + xRotation); 

     for (unsigned int i = 0; i < agents.size(); i++) 
     { 
      //if (D3DXVec3Length(agents[i].MainLegsPosition() - Position()) < TOLERANCE && isPresent)//right here 
      //{     
      // addAmmo(agents[i].Index()); 
      // isPresent = false; 
      //} 
     } 

     if (isPresent == false) 
     { 
      Regenerate(); 
     } 
    } 

    /*void Pickup::Draw(D3DXMATRIX matView, D3DXMATRIX matProjection, ID3D10Effect* effect)//right here 
    { 
     if (isPresent == true) 
     { 
      Draw(matView, matProjection, effect); 
     } 
    }*/ 

    // getters 
    int Pickup::Index() 
    { 
     return index; 
    } 

    int Pickup::NodeIndex() 
    { 
     return nodeIndex; 
    } 

    bool Pickup::IsPresent() 
    { 
     return isPresent; 
    } 

/*  vector<Agent>& Pickup::Agents() 
    { 
     return agents; 
    }*/ 

    // setters 
    void Pickup::Index(int index) 
    { 
     this->index = index; 
    } 

    void Pickup::NodeIndex(int nodeIndex) 
    { 
     this->nodeIndex = nodeIndex; 
    } 

ヘッダー:

#ifndef PICKUP_H 
#define PICKUP_H 

#include "gameObject.h" 
#include "Agent.h" 
#include <vector> 

using namespace std; 

class Pickup : public GameObject 
{ 
private: 

    int count; 

    int index; 

    int nodeIndex; 

    bool isPresent; 

    D3DXVECTOR3 xRotation; 

    const float TOLERANCE; 

    void Regenerate(); 

protected: 

    vector<Agent>& agents; 

public: 

    Pickup(vector<Agent>& agents); 

    virtual void addAmmo(int agentIndex); 

    void Update(); 

    void Draw(); 

    // getters 
    int Index(); 

    int NodeIndex(); 

    bool IsPresent(); 

    // setters 
    void Index(int index); 

    void NodeIndex(int nodeIndex); 
}; 

#endif 
+0

エラーメッセージは2行目に進むのではなく、突然終了しますか? –

+0

'ベクター&'メンバーが本当に必要ですか?さらに、エラーとコンパイラの出力を2つのウィンドウに一覧表示するIDEにある場合、エラーの最初の行を取得しているだけかもしれません。しかし、Henrikの答えはおそらく正しいでしょう。 – ssube

答えて

4

メンバーagentsが初期化されていません。

+0

私は信じられないほど愚かな私!ありがとうございました。 – SirYakalot

0

コンストラクタは、属性 'agents'を初期化しません。コンストラクタの初期化リストで初期化する必要があります。また、値を代入するのではなく、初期化リスト(count、index、nodeIndex、...)のすべての属性を初期化することをお勧めします。

ところで、なぜ「エージェント」属性が保護されていますか?それはプライベートでなければなりません。派生クラスによる属性の直接変更を許可しないでください。それは乱雑なコードを避ける。

乾杯。

関連する問題