我很久以来就遇到了错误,接下来,我正在学习,我想我不明白这个错误.
droid.cpp: In function ‘std::ostream& operator<<(std::ostream&, const Droid&)’:
droid.cpp:94:30: error: passing ‘const Droid’ as ‘this’ argument of ‘std::string
Droid::getId()’ discards qualifiers
[-fpermissive]
Run Code Online (Sandbox Code Playgroud)
第94行:
std::ostream& operator<<(std::ostream &os, Droid const & a)
os << "Droid '" << a.getId() << "', " << *a.getStatus() << ", " << a.getEnergy() << std::endl;
Run Code Online (Sandbox Code Playgroud)
和听众:
std::string getId();
Run Code Online (Sandbox Code Playgroud)
我对"operator <<",a.getId,a.getStatus,a.getEnergy中的3个调用有相同的错误.
有人可以向我解释一下编译器在说什么吗?
我正在为我的游戏开展响应式设计.我根据屏幕尺寸重新计算对象的位置.我正在做好的计算,但我的函数给我错误的结果总是返回0.我需要返回值为Int.
这里的代码:
public int rdnW(int a)
{
double b;
b = (a / 800 * 100);
return (int)(b * Widths / 100);
}
Run Code Online (Sandbox Code Playgroud)
有了断点,我看到b总是= 0; 在我的情况下a = 258.谢谢