是否可以通過知道其地址獲取容器中成員的索引?下面是描述所需內容的代碼。從其地址獲取成員的索引
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
struct Point {};
struct Triangle
{
vector<reference_wrapper<Point>> p;
};
int main()
{
vector<Point> p (3);
Triangle t;
t.p.push_back (ref(p[0]));
t.p.push_back (ref(p[1]));
t.p.push_back (ref(p[2]));
// push_back order may be random
for (unsigned int i=0; i<t.p.size(); ++i)
{
// print index of t.p.get() in vector<Point>p
}
return 0;
}