So i'm creating this class which contains a string, the class handles creating sprites setting their icon etc etc but I'm running into an error.
Here's the class code:
class staticmob{
public:
sf::Sprite icon;
sf::Texture iconTexture;
std::string object_name;
bool density = false;
staticmob(sf::Sprite mIcon,
std::string mName,
std::string fileName,
const bool dense,
bool inObjList,
turf *object_list);
};
where the error is:
staticmob midGround(sf::Sprite midGround,
"Ground",
"tileset.png",
true,
true,
background);
the error:
error: expected identifier before string constant
error: expected ',' or '...' before string constant
any help is much appreciated (yes, i'm slighty a newbie in C++ but i'm getting the hang of it)
在staticmob midGround的构造中,您要重新声明第一个参数的类型(sf :: Sprite部分-复制/粘贴错误?),并且注释中还涉及到名称冲突(midGround是staticmob吗?您要声明它,还是sf :: Sprite实例?)假设midGroundSprite实际上是sf :: Sprite的名称,类似这样的方法应该起作用:
staticmob midGroundMob(midGroundSprite, "Ground", ... etc.)
Your error is similar to what you will see if you compile:
void foo(int, int) {}
int main()
{
foo(int i, 0); // "int i" is not an expression. It is not a declaration either.
return 0;
}
What you need is something along the lines of:
sf::Sprite midGroundSprit;
staticmob midGround(midGroundSprite,
"Ground",
"tileset.png",
true,
true,
background);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.