Pav*_*kin 3 c++ const-correctness visual-c++ stdset c++14
示例代码:
#include <string>
#include <set>
using namespace std;
class x
{
private:
int i;
public:
int get_i() const { return i; }
};
struct x_cmp
{
bool operator()(x const & m1, x const & m2)
#if _MSC_VER
const
#endif
{
return m1.get_i() > m2.get_i();
}
};
std::set<x, x_cmp> members;
void add_member(x const & member)
{
members.insert(member);
}
Run Code Online (Sandbox Code Playgroud)
调用:
$ g++ -c -std=c++14 -pedantic -Wall -Wextra
<nothing>
$ clang++ -c -std=c++14 -pedantic -Wall -Wextra
<nothing>
$ icc -c -std=c++14 -pedantic -Wall -Wextra
<nothing>
$ cl /c /std:c++14 /Za
<nothing>
Run Code Online (Sandbox Code Playgroud)
问题:为什么msvc需要const而其他的不需要?或者为什么其他人不需要const?
| 归档时间: |
|
| 查看次数: |
345 次 |
| 最近记录: |