2011-04-14 125 views
0

有一些問題與此for循環來繪製同一對象的多個號碼繪製的對象,通過陣列

for (int i = BALL_RED_START; i<BALL_RED_END;i++) 
{ 
    glColor3f(1,0,0); 
    Redball[i].Draw(); 
} 

Redball正在從一個單獨的類叫做,

I get error:2228, left of .Draw must have class/struct/union. 

Redball是在Main.cpp的

Ball Redball; 

Ball.cpp頂部定義:

include "Ball.h" 
include "Vector2f.h" 
include "Vector3f.h" 
include "Glut/glut.h" 
include "GL/gl.h" 
include "GL/glu.h" 

Ball::Ball(void) 
{ 
    Vector3f Temp_position; 
    position = Temp_position; 
    Vector3f Temp_velocity; 
    velocity = Temp_velocity; 
} 

Ball::~Ball(void) 
{ 
} 

void Ball::SetPos(Vector3f New_position) 
{ 
    position = New_position; 
} 

void Ball::Draw() 
{ 
    glPushMatrix(); 
    glTranslatef(position.X(), position.Y(), position.Z()); 
    glColor3d(1, 0, 0); 
    glutSolidSphere(0.3, 50, 50); 
    glPopMatrix(); 
} 

void Ball::SetVel(Vector3f New_velocity) 
{ 
    velocity = New_velocity; 
} 

Vector3f Ball::GetPos() 
{ 
    Vector3f temp; 
    temp = position; 
    return temp; 
} 

只是想畫出這些球8。

+0

你不覺得我們想知道左側的.Draw _is_是什麼嗎?我的朋友是如何宣佈Redball的? – sehe 2011-04-14 17:28:58

+0

我試過了 - >至今沒有運氣! – 2011-04-14 17:52:36

+0

也許當我有更多的信息時,我會對[我的回答]發表評論(http://stackoverflow.com/questions/5667147/drawing-an-object-through-an-array/5667177#5667177)必須經常檢查回來 – sehe 2011-04-14 19:36:06

回答

3

也許你需要這個

Redball[i]->Draw(); 

但是也沒有辦法告訴

從你給我們

+0

恐怕更新(thx)仍然沒有起到關鍵作用。頭文件可能爲Ball定義了operator [](...),這是關鍵的缺失位:) – sehe 2011-04-14 19:36:25

2

的代碼錯誤意味着。訪問器是用於真實數據的。結構在這種情況下,類或非全局函數有一個指向你的類的指針,而不是一個實例。

嘗試,看看是否適合你。

Redball[i]->Draw()