2014-08-27 75 views
-1

我不斷收到此錯誤C: Users Joshua Desktop Game Projects SFML projects Test Render.cpp | 15 | error:'class std :: vector <Character>'has no member named'getSprite'|

C:\Users\Joshua\Desktop\Game Projects\SFML projects\Test\Render.cpp|21|error: 'class std::vector<Character>' has no member named 'getSprite'| 

我試圖接受包含類型Characterpointers一個vector。包含正確的頭文件,所以這不是問題。我一直試圖弄清楚大約過去的一個小時左右,但我完全失去了。我以爲我做對了。非常感謝!

void Render::draw(sf::RenderWindow* window, std::vector<Character>* foreground, std::vector<Character>* background, std::vector<Character>* scenery) 
{ 

window->clear(); 
for(int a = 0; a<scenery->size(); a++) 
{ 

    window->draw(scenery[a].getSprite()); 

} 
for(int b = 0; b<background->size(); b++) 
{ 

    window->draw(background[b].getSprite()); 

} 
for(int c = 0; c<foreground->size(); c++) 
{ 

    window->draw(foreground[c].getSprite()); 

} 

window->display(); 

} 
+4

你傳入指針的載體。想想你將'operator []'應用到指針會發生什麼。 – juanchopanza 2014-08-27 14:38:09

+0

它試圖訪問或創建'指針'數組''? – Joshua 2014-08-27 14:39:43

+1

它將它視爲一組向量。更好地通過參考傳遞。 – juanchopanza 2014-08-27 14:41:56

回答

1

如何:

void Render::draw(sf::RenderWindow* window, std::vector<Character>* foreground, std::vector<Character>* background, std::vector<Character>* scenery) 
{ 

window->clear(); 
for(int a = 0; a<scenery->size(); a++) 
{ 

    window->draw((*scenery)[a].getSprite()); 

} 
for(int b = 0; b<background->size(); b++) 
{ 

    window->draw((*background)[b].getSprite()); 

} 
for(int c = 0; c<foreground->size(); c++) 
{ 

    window->draw((*foreground)[c].getSprite()); 

} 

window->display(); 

} 
相關問題