C++ 是std::max_元素a C++;11 x功能?
您知道std::max_元素是C++11特性还是以前存在过 那个。 我使用的是g++4.8.3,不会抛出警告消息,请求使用-std=c++11 我发布代码是为了帮助人们在机器上编译:C++ 是std::max_元素a C++;11 x功能?,c++,c++11,C++,C++11,您知道std::max_元素是C++11特性还是以前存在过 那个。 我使用的是g++4.8.3,不会抛出警告消息,请求使用-std=c++11 我发布代码是为了帮助人们在机器上编译: #include <iostream> #include <vector> #include <algorithm> #include <vector> class A { public: int x; explicit A(
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
class A
{
public:
int x;
explicit A(int x): x(x) {}
bool operator<(const A& a) { return x < a.x; }
};
int
main()
{
std::vector<A> v;
v.push_back(A(20));
v.push_back(A(10));
v.push_back(A(15));
v.push_back(A(5));
A result(*(std::max_element(v.begin(), v.end())));
std::cout << result.x;
return 0;
}
#包括
#包括
#包括
#包括
甲级
{
公众:
int x;
显式A(intx):x(x){}
bool操作符std::max_元素
从第一个C++标准开始就存在了。是什么阻止了您简单地查找它?或者在C++03中尝试它?很抱歉。它确实是用C++03编译的。