Search code examples
vectorpush-back

2 arguments in push_back


I am trying to put 2 arguments inside a vector using push_back but its giving me an error since the function is allowed to take only one argument. How can I pass 2 arguments??

Vertex Class:

template <class VertexType, class EdgeType> class Vertex{
public:
std::vector<std::pair<int, EdgeType>> VertexList;
};

Outside Vertex Class inside Main():

project3::Vertex<string, string> v1("v1");
v1.VertexList.push_back(1,"e1");

Error is :

error C2661: 'std::vector<_Ty>::push_back' : no overloaded function takes 2 arguments IntelliSense: too many arguments in function call


Solution

  • You need to do

    v1.VertexList.push_back(std::pair<int, EdgeType>(1,"e1"));