所以我创建了这个包含字符串的类,该类处理创建精灵设置他们的图标等等但是我遇到了错误。
这是类代码:
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);
};
错误是:
staticmob midGround(sf::Sprite midGround,
"Ground",
"tileset.png",
true,
true,
background);
错误:
error: expected identifier before string constant
error: expected ',' or '...' before string constant
任何帮助都非常感激(是的,我在C ++中是一个新手,但我已经掌握了它)
答案 0 :(得分:0)
在构建 staticmob midGround 时,你是在重新声明第一个参数的类型(sf :: Sprite部分 - 复制/粘贴错误?),还有注释中触及的名称冲突(是想要声明的staticmob的midGround,还是sf :: Sprite实例?)假设midGroundSprite实际上是sf :: Sprite的名称,这样的东西应该有效:< / p>
staticmob midGroundMob(midGroundSprite, "Ground", ... etc.)
答案 1 :(得分:0)
您的错误与编译时的错误类似:
void foo(int, int) {}
int main()
{
foo(int i, 0); // "int i" is not an expression. It is not a declaration either.
return 0;
}
您需要的是:
sf::Sprite midGroundSprit;
staticmob midGround(midGroundSprite,
"Ground",
"tileset.png",
true,
true,
background);