功能2倍的值是這個如何分離的函數返回到返回值2個不同的變量,C++
float calcVelocity(float xacceleration, float yacceleration,sf::Clock clock, float originalDistance){
sf::Time time = clock.getElapsedTime(); //get current time and store in variable called time
float xvelocity = xacceleration*time.asSeconds();
float yvelocity = yacceleration*time.asSeconds();
while (!(originalDistance + calcDisplacement(yacceleration, clock, originalDistance) <= 0)) {
time = clock.getElapsedTime(); //get current time and store in variable called time
xvelocity = xacceleration*time.asSeconds();//Calculates velocity from acceleration and time
yvelocity = yacceleration*time.asSeconds();
cout << xvelocity<<endl;//print velocity
cout << yvelocity << endl;
system("cls");//clear console
}
return xvelocity;
return yvelocity;
}
那麼我想他們while循環後打印爲finalXvelocity =胡說和finalYvelocity =胡說是完成的。在我調用函數並輸出結果的主代碼中,它將兩個值一起打印出來。例如,finalXvelocity = blahblah。
我想我可以分開返回到主代碼的值,然後使用這些打印出來,但我不知道該怎麼做。
感謝
['std :: pair'](http://en.cppreference.com/w/cpp/utility/pair)(via ['std :: make_pair()'](http://en.cppreference的.com /瓦特/ CPP /效用/對/ make_pair))。 – BoBTFish
@BoBTFish:把它寫成答案! –