Hi.
Im new to c++, and have currently a problem mapping my object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include "dag.h"
#include "dagnode.h"
#include <limits>
#include <map>
using std::cout;
using std::endl;
using std::map;
using namespace std;
map<int, dagnode> dagnodeMap;
int idCounter = 0;
/******************************
* At construction is root made
******************************/
dag::dag() {
makeVersion({}, 0);
}
/*******************************************
* Makes a new version node,
* and connect it bidirected with ancestors
* if ancestor i null, then it is a root
*******************************************/
void dag::makeVersion(dagnode *a, int numberOfAncestors){
idCounter = idCounter+1;
int id = idCounter;
dagnode* newnode = new dagnode(id, a);
fprintf(stderr, "dagnode id: %d \n", newnode->getId());
for (int i = 0; i < numberOfAncestors; i++){
dagnode ancestor = a[i];
if(a[i].getChilds() == 0){
//No child exist earlier
a[i].setChilds({newnode});
fprintf(stderr, "Added first child\n");
} else {
dagnode child1 = a[i].getChilds()[0];
dagnode newChildList[] = {child1,*newnode};
a[i].setChilds(newChildList);
fprintf(stderr, "Added second child\n");
}
}
dagnodeMap[newnode->getId()] = *newnode;
}
|
At the second last line im trying to save a instance of my object to my map. But it gives an error:
/usr/include/c++/4.6/bits/stl_map.h: In member function ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int, _Tp = dagnode, _Compare = std::less<int>, _Alloc = std::allocator<std::pair<const int, dagnode> >, std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = dagnode, std::map<_Key, _Tp, _Compare, _Alloc>::key_type = int]’:
../DAG/dag.cpp:55:29: instantiated from here
/usr/include/c++/4.6/bits/stl_map.h:453:11: error: no matching function for call to ‘dagnode::dagnode()’
/usr/include/c++/4.6/bits/stl_map.h:453:11: note: candidates are:
../DAG/dagnode.h:16:2: note: dagnode::dagnode(int, dagnode*)
../DAG/dagnode.h:16:2: note: candidate expects 2 arguments, 0 provided
../DAG/dagnode.h:14:7: note: dagnode::dagnode(const dagnode&)
../DAG/dagnode.h:14:7: note: candidate expects 1 argument, 0 provided
make: *** [DAG/dag.o] Error 1
The object dagnode have an constructor, but i dont expect that should give any problem.
Are there any who can help me please.
Thanks a lot.