将成员函数作为构造函数参数调用时出错 "Variable is not a type name"

Error calling member function as constructor parameter "Variable is not a type name"

本文关键字:is Variable not name type 出错 函数 成员 构造函数 调用 参数      更新时间:2023-10-16

我想将本地实例的成员函数的输出作为构造函数的参数传递。我正在使用 SFML 库。

鲍尔·

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;
}

主.cpp

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(("触发。我的调试器显示"窗口不是类型名称"。

该错误是由构造函数定义引起的,您在其中获取sf::Vector2f _origin参数,然后window.getSize()返回sf::Vector2U。尝试将参数更改为sf::Vector2U _origin