[英]Cannot construct Vector2f object inside struct using SFML
Hi im getting error when trying this code: 您好,尝试此代码时出现错误:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
const float ballVelocity = 8.f;
struct Ball
{
Vector2f velocity(-ballVelocity, -ballVelocity);
};
I'm using SFML and doing it by a tutorial, and it is supposed to work, but Visual Studio sais that in this line: 我正在使用SFML并通过教程进行操作,应该可以使用,但是Visual Studio在这一行中表示:
Vector2f velocity(-ballVelocity, -ballVelocity);
Expected a type specifier. 预期类型说明符。
(EDIT: to be clear Im trying to create object of Vector2) (编辑:要明确我试图创建Vector2的对象)
If you're trying to use non-static data member initialization, you cannot do it like that. 如果您尝试使用非静态数据成员初始化,则不能那样做。 You need to either use brace initialization, or equal(=) initialization.
您需要使用括号初始化或equal(=)初始化。 Either of these should work:
这些都应该起作用:
struct Ball
{
Vector2f velocity {-ballVelocity, -ballVelocity};
};
Or this: 或这个:
struct Ball
{
Vector2f velocity = Vector2f(-ballVelocity, -ballVelocity);
};
Although, if I'm not mistaken, the components of SFML exist in the sf
namespace, so any references to Vector2f
actually need to be qualified as sf::Vector2f
. 虽然,如果我没记错的话,SFML的组件存在于
sf
名称空间中,所以实际上对Vector2f
任何引用都需要限定为sf::Vector2f
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.