[英]What if a constructor parameter has the same name as a member variable in C++?
[英]Error calling member function as constructor parameter “Variable is not a type name”
我想將本地實例的成員 function 的 output 作為構造函數的參數傳遞。 我正在使用 SFML 庫。
球.h
Ball(sf::Vector2f _dvelocity, sf::Vector2f _position, sf::Vector2f _origin, sf::Texture _texture, float _dvmagnitude )
{
dvelocity = _dvelocity;
position = _position;
sprite.setTexture(_texture);
sprite.setOrigin(_origin);
dvmagnitude = _dvmagnitude;
}
主文件
sf::RenderWindow window(sf::VideoMode(640, 480), "Pong");
sf::Event event;
sf::Texture pongTexture;
pongTexture.loadFromFile("frost mage.PNG");
Ball ball(sf::Vector2f _dvelocity(), sf::Vector2f _position(), window.getSize(), pongTexture, 1);
該錯誤是由 main.cpp 最后一行中的“window.getSize()”觸發的。 我的調試器顯示“window 不是類型名稱”。
該錯誤是由您的構造函數定義引起的,您在其中使用sf::Vector2f _origin
參數,然后window.getSize()
返回sf::Vector2U
。 嘗試將您的參數更改為sf::Vector2U _origin
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.