1

I am currently working on a rudimentary simulator for the game Boggle, and right now I have gotten to the point where I need to use pointers to an object in a function call. However, I am unsure of how to do this, and thus far my search on this site and elsewhere has not proved fruitful, seeing as from what I have seen the questions have not been about pointers to objects. The following is my code for the function being called from a class, the initialization of the objects, and my attempted function calls. The setAdjacency function is found in the class boggleNode.

void setAdjacency(boggleNode * topleft = NULL, boggleNode * top = NULL,    boggleNode * topright = NULL, 
boggleNode * left = NULL, boggleNode * right = NULL, boggleNode *  botleft = NULL, boggleNode *  bot = NULL, boggleNode *  botright = NULL){
    adjacency[0] = topleft;
    adjacency[1] = top;
    adjacency[2] = topright;
    adjacency[3] = left;
    adjacency[4] = right;
    adjacency[5] = botleft;
    adjacency[6] = bot;
    adjacency[7] = botright;             //For keeping track of which nodes  are adjacent to which other ones. 
}

These are the private variables in boggleNode:

private:
boggleNode * adjacency[8];
char letter;
bool isUsed;

"Board" is defined as follows:

boggleNode * board = new boggleNode[16];

And finally, here is where I attempt to call the adjacency function in my main function:

board[0].setAdjacency(board[1], board[4], board[5]);  

I am aware that currently the arguments in this function call are references, whereas they are supposed to be pointers in the function definition. How do I get the function call and the function definition to align properly?

2
  • Do you have a compiler error you can post? Commented Aug 14, 2015 at 23:42
  • I am aware that currently the arguments in this function call are references I don't see references in that call. You are passing boggleNode instances. Maybe you are getting confused with Java? Commented Aug 14, 2015 at 23:47

2 Answers 2

1

The value of a pointer to object is the address of the object. To get the address of the object, you need to use the "addressof" operator: &

board[0].setAdjacency(&board[1], &board[4], &board[5]);
Sign up to request clarification or add additional context in comments.

Comments

0

I got some help from a friend of mine, and I figured out the answer. I needed to use "addressof" operator plus extra parentheses (for instance, &(board[0]) ).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.