使用矢量对

时间:2016-05-29 21:18:40

标签: c++ vector std-pair

我有代码kruskal算法(MST)并使用这样的对矢量

vector<pair<int,pair<int,int> > > v;

我想添加wight并制作像这样的源,目标对

v.push_back(make_pair(wight,make_pair(src,des)));

然后

sort(v.begin(),v.end());

因为它首先根据x坐标排序,然后是y坐标

它出现了错误

error: request for member ‘push_back’ in ‘v’, which is of non-class type ‘int’
   v.push_back(MK(wt,MK(x,y)));
     ^

    error: request for member ‘begin’ in ‘v’, which is of non-class type ‘int’
      sort(v.begin(),v.end());
             ^

    error: request for member ‘end’ in ‘v’, which is of non-class type ‘int’
      sort(v.begin(),v.end());
                       ^

我正在学习如何使用c ++ STL并且厌倦了调试它。那么我如何推动对并对这个向量进行排序呢?

我的代码链接。 https://ideone.com/obEhP0

1 个答案:

答案 0 :(得分:0)

您的mainint v, e;开头。因此,对v的引用会看到int而不是vector

(旁白:那些宏。不要这样做。真的。它们阻碍而不是帮助可读性,并且有各种各样的缺点。)