I am getting compilation error while inserting values inside constructor Monitor counstructor. Could you suggest what could be approach for the same as I need to populate this vector during class instantiation. It works fine with below approach but I don't want to populate the vector separately.
vect1.insert( make_pair(10,20) );
vect1.insert( make_pair(30,49) );
vect1.insert( make_pair(50,60) );
vect1.insert( make_pair(70,80) );
below is the code snippet
#include <iostream>
#include <vector>
#include<algorithm>
#include<memory>
#include <set>
using namespace std;
class Monitor
{
public:
virtual ~Monitor() = default;
explicit Monitor(
const set< pair <double,double> > &vect1
)
{
for (auto &itr : vect1 )
{
std::cout<<"value1 ="<<itr.first<<endl;
std::cout<<"value2="<<itr.second<<endl;
}
}
};
int main()
{ set< pair <double,double> > vect1;
Monitor obj (vect1.insert( make_pair(10,20) ));
return 0;
}
compilation error
error: no matching function for call to ‘Monitor::Monitor(std::pair >, bool>)’
Monitor obj (vect1.insert( make_pair(10,20) ));
Aucun commentaire:
Enregistrer un commentaire