2012-04-11 18 views
-2

2Dベクトルのサイズを調べるのに質問があります。私の単純な質問は、各形状に3つの "形状"を記憶しているベクトルがあり、それぞれの形状がランダムな数のヒットポイント(デカルト座標{x、y、z}として記憶されている)を持ち、各ヒットポイントはランダムな色各形状にどのくらいのヒットポイントがあるか調べたい私が行う場合:2Dベクトルのサイズを調べる

VectorOfShapes.size() 

が、私は答え

3 

を得るこれは here前に尋ねた同様の質問です。しかしそれは私を助けませんでした。彼らのソリューションは

VectorOfShapes[1].size() 

だった私はそれを試してみましたが、私は次のようなエラー「error C2228: left of '.size' must have class/struct/union 」を得ました。どちらがうまく答えられましたか(リンクに従ってください)。それはまだ私(または私は愚かな)を助けることはありません... 任意のアイデア? fluxsの宣言を提供したコメントに基づいて

//は----------情報を追加

class World { 
public: 
vector<Flux*> VectorOfShapes; 
void 
containers(int obnum, Ray reflect, RGBColor Ll); 
void      
build(void); 
void 
add_vectorshape(Flux* vectorshape_ptr) 
private: 
void 
delete_VectorOfShapes 
} 
inline void 
World::add_vectorshape(Flux* vectorshape_ptr){ 
VectorOfShapes.push_back(vectorshape_ptr); 
} 

void 
World::containers(int obnum, Ray reflect, RGBColor Ll) 
{ 
vectorOfShapes[obnum]->push(reflect); 
VectorOfShapes[obnum]->push(Ll); 
int sizers = VectorOfShapes[0].size(); //this is where the code is giving me errors 
} 

void             
World::build(void) { 
Flux* vectorshape_ptr1 = new Flux; 
add_vectorshape(vectorshape_ptr1); 
Flux* vectorshape_ptr2 = new Flux; 
add_vectorshape(vectorshape_ptr2); 
Flux* vectorshape_ptr3 = new Flux; 
add_vectorshape(vectorshape_ptr3); 
} 

void 
World::delete_VectorOfShapes(void) { 
int num_VectorOfShapes = VectorOfShapes.size(); 

for (int j = 0; j < num_VectorOfShapes; j++) { 
    delete VectorOfShapes[j]; 
    VectorOfShapes[j] = NULL; 
} 

VectorOfShapes.erase (VectorOfShapes.begin(), VectorOfShapes.end()); 
} 

    class Flux{ 

public: 
std::vector<Ray> rays; 
std::vector<RGBColor> L; 


void push(Ray ray); 
void push(RGBColor Ls) ; 


}; 
inline void 
Flux::push(Ray ray) { 
rays.push_back(ray); 
} 

inline void 
Flux::push(RGBColor Ls){ 
L.push_back(Ls); 
} 
+2

あなたは 'VectorOfShapes'の宣言を投稿できますか? – hmjd

+1

'VectorOfShapes [1] .size'では、' .size'はおそらく変数ではなくメソッドなので、 'VectorOfShapes [1] .size()'のように呼び出す必要があります。しかし、「VectorOfShapes」は何もなしで伝えるのは難しいです。 – karlphillip

+0

'float HitPoints = VectorOfShapes [0] .x + VectorOfShapes [0] .y + VectorOfShapes [0] .z'? – Cyclonecode

答えて

1

vector<Flux*> fluxs; 

fluxsを意味し、ポインタのベクトルであります:

fluxs[i] 

戻りFlux*、ないFlux属性を設定するための投稿コードで行ったように、->を使用する必要があります。 Fluxの定義がなければ、私はhitpointsを得るために、あなたはちょうどそうfluxsにヒットポイントの合計を取得するには、fluxsでちょうど3つの要素がある可能性が述べたようにゲッターがあると仮定しています:

​​

EDIT:

を次いで

ヒットポイントカウントがFlux::rays(又はFlux::L)内の要素の数である場合:

int total_hitpoints = fluxs[0]->rays.size() + 
         fluxs[1]->rays.size() + 
         fluxs[2]->rays.size(); 
関連する問題