小编Gab*_*son的帖子

将'const'作为'this'参数传递错误

我很久以来就遇到了错误,接下来,我正在学习,我想我不明白这个错误.

 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个调用有相同的错误.

有人可以向我解释一下编译器在说什么吗?

c++ g++ compiler-flags

3
推荐指数
1
解决办法
8705
查看次数

不能做一个简单的划分

我正在为我的游戏开展响应式设计.我根据屏幕尺寸重新计算对象的位置.我正在做好的计算,但我的函数给我错误的结果总是返回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.谢谢

c# xna function division

0
推荐指数
1
解决办法
1455
查看次数

标签 统计

c# ×1

c++ ×1

compiler-flags ×1

division ×1

function ×1

g++ ×1

xna ×1