Pointer problem

Hi.
I am currently having a problem with pointers to some objects. Suddently the variables on the objects return large unexpected integers, which I assume may result in a pointer problem.

Data flow is a bit complicated but i hope you can see what I am doing:

1
2
3
4
5
6
7
..
//We get the object:
dagnode* ancestorDagNode = globalDag->getVersionNode(ancestorId);
...
//We send it as a array to another function:
globalDag->makeVersion({ancestorDagNode},1,newNode);
...


in globalDag->makeVersion we have:
1
2
3
4
5
6
7
8
9
10
11
void dag::makeVersion(dagnode a[], int numberOfAncestors, LocalVersionNode *rootNode){
	
...

  for (int i = 0; i < numberOfAncestors; i++){
	  a[i].addChild(newnode);
	  newnode->addAncestor(&a[i]);
  }

...
}



In addAncestor we have:

1
2
3
4
5
6

void dagnode::addAncestor(dagnode * a) {
	ancestors[numberOfAncestors] = a;
	numberOfAncestors++;
}



No error is found by doing this, but then i later want to get the objects again. I then call this method:

1
2
3
4
5
6

dagnode* dagnode::getAncestors(){
	fprintf(stderr, "res: %d\n", ancestors[0]->getId());
	return *ancestors;
}



The problem is that the output is:
res: 4224362

however i assumed: res: 2.


Can any find the pointer error?
ancestorDagNode has type dagnode*. You use it to initialize an element of an array of type dagnode

globalDag->makeVersion({ancestorDagNode},1,newNode);

( void dag::makeVersion(dagnode a[], int numberOfAncestors, LocalVersionNode *rootNode) )
Last edited on
Hey.
Thanks a lot. I fixed it by using
 
dagnode* ancestorDagNode[2] = {globalDag->getVersionNode(ancestorId)};


instead. This ment that i of coarse also should fix the parameters at the functions, but then it was perfect
Topic archived. No new replies allowed.