我傳遞使用SFML吸氣功能像一個參考參數傳遞一個引用參數時:意外行爲使用getter函數
ball.update(時間,pad_player.getGlobalBounds(),pad_ia.getGlobalBounds(),得分);
,但出現這樣的問題:
Pong.cpp: In member function ‘void Pong::run()’:
Pong.cpp:30:82: error: no matching function for call to ‘Ball::update(sf::Time&, sf::FloatRect, sf::FloatRect, Score&)’
ball.update(time, pad_player.getGlobalBounds(), pad_ia.getGlobalBounds(), score);
^
Pong.cpp:30:82: note: candidate is:
In file included from Pong.hpp:5:0,
from Pong.cpp:2:
Ball.hpp:10:7: note: void Ball::update(sf::Time&, sf::FloatRect&, sf::FloatRect&, Score&)
void update(sf::Time& delta, sf::FloatRect& p1, sf::FloatRect& p2, Score& score);
^
Ball.hpp:10:7: note: no known conversion for argument 2 from ‘sf::FloatRect {aka sf::Rect<float>}’ to ‘sf::FloatRect& {aka sf::Rect<float>&}
所以如果我改變了這一點:
sf::FloatRect player = pad_player.getGlobalBounds();
sf::FloatRect ia = pad_ia.getGlobalBounds();
ball.update(time, player, ia, score);
程序運行正常。
爲什麼?
我想我們需要更多的細節! – Carles 2014-09-05 12:12:59