Quote:
Yes, but now that I think about it, maybe it would be better if you could just expose a set "name" of classes. For example, a class "guy" with thousands of variables could expose just "name", "age" and "sex", wich would semantically mean "I got a name, i got a age, and i have a sex". That's not private info. So someone would later be able to call: "guy, give me your name" (guy.get(guy::name)) or "guy, give me your age" (guy.get(guy::sex)).
...public: std::string name; int age; sex_t sex;private: // rest of members...
What's your point? That's exactly what public does.
Quote:
But then I would have to write another function for every new variable I want bullet to be able to be sorted from, wich would be almost a copy from the previous function. In the end I would have thousand of functions that are just the same thing, when I could just call container.sort(speed,asc).
A little bit of magic:
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cassert>struct obj_t{ int num; std::string str; obj_t(int num, const std::string &str): num(num), str(str) {}};template<typename T>struct objPred{ T const obj_t::*var; objPred(T const obj_t::*var): var(var) {} bool operator()(const obj_t &a, const obj_t &b) const { return a.*var < b.*var; }};int main(){ std::vector<obj_t> list; list.push_back(obj_t(42, "abc")); list.push_back(obj_t(12, "bca")); // sort by "num" variable std::sort(list.begin(), list.end(), objPred<int>(&obj_t::num)); assert(list[0].num == 12); assert(list[1].num == 42);}