undefined reference to `printMemory(int*, int (*) [7])'|

I'm having problems compiling my program. I've encountered this error:
 
 undefined reference to `printMemory(int*, int (*) [7])'| 


For full disclosure, this is a CS1 project for school.

I have no clue how to solve it. I don't even know what this error is talking about. It's so cryptic. The error is on line 97.

Here's my code:

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<cctype>
using std::cout;
using std::cin;
using std::endl;
using std::fstream;

//gameArray indicies
//gameArray[0] = players current room
const int CURRENT_ROOM_INDEX = 0;

//gameArray[1] = current room of zombie
const int ZOMBIE_ROOM_INDEX = 1;

//gameArray[2]
const int NUM_BULLETS_INDEX = 2;

//gameArray[3]
const int NUM_ROOMS_INDEX = 3;

//boolean whether player has grail or not
const int HAVE_GRAIL_INDEX = 4;

//roomArray indices
//roomArray[gameArray[CURRENT_ROOM_INDEX]][4] = 1 or 0 if the player is
//or is not in the current room
const int PLAYER_INDEX = 4;

//roomArray[gameArray[ZOMBIE_ROOM_INDEX]][5] = 1, tracks where the zombie is
const int ZOMBIE_INDEX = 5;

//roomArray[room][6] = the room that the grail is in should be marked 1, all others 0
const int GRAIL_INDEX = 6;

// the number of rooms and number of bullets to fend off the zombies
const int MAX_ROOMS = 11;
const int MAX_BULLETS = 6;

//********************************************************************************************************************************************
//PART 1A prototypes
//reset simply resets the primary game variables
void reset(int &currentRoom, int &zombieRoom, int &numBullets, int &numRooms, bool &haveGrail);

//print game instructions
void instructions();

//print layout of game memory
void printMemory(int gameArray[],int roomArray[][7]);

// the menu (which calls functions printMemory and instructions)
bool menu(int &currentRoom, int &zombieRoom, int &numBullets, int &numRooms, bool &haveGrail, int gameArray[],int roomArray[][7]);
//********************************************************************************************************************************************

//PART 1B prototypes
//read in the input file for the map

void readMaze(int roomArray[][7], int gameArray[5]);

//return a random room
int getRandomRoom(int gameArray[5]);

//place the zombie
void placeZombie(int roomArray[][7], int gameArray[5]);

//place the grail
void placeGrail(int roomArray[][7], int gameArray[5]);

// the setup function
void setup(int &currentRoom, int &zombieRoom, int &numBullets, int &numRooms, bool &haveGrail, int roomArray[][7], int gameArray[5]);
//*********************************************************************************************************************************************

//PART 2 prototypes

//PART 3 prototypes

int main()
{
	// these variables are passed throughout this program
	int roomArray[MAX_ROOMS][7],
	    gameArray[5],
	    currentRoom = 0,
       zombieRoom = 0,
       numBullets = 0,
       numRooms = 0;

	int menuSelection = 0;
    bool Menu = false;
    bool haveGrail = false;

	reset(currentRoom, zombieRoom, numBullets, numRooms, haveGrail);

   do
   {
        Menu = menu(currentRoom, zombieRoom, numBullets, numRooms, haveGrail,  gameArray, roomArray);     //ERROR RIGHT HERE
   } while (Menu);


	return 0;
}
// build your functions here. Don't forget your pre and post conditions
//pre: no preconditions
//post: resets primary game variables
void reset(int &currentRoom, int &zombieRoom, int &numBullets, int &numRooms, bool &haveGrail)
{
    currentRoom = 0;
    zombieRoom = 0;
    numBullets = 0;
    numRooms = 0;
    haveGrail = false;

}



//pre: no preconditions
//post: displays a menu which calls printMemory and instructions
bool menu(int &selection)
{
    int gameArray[0];
    int roomArray[gameArray[CURRENT_ROOM_INDEX]][7];

    cout << "       Enter, if you dare...\n";
    cout << "*** THE TOMB OF THE BLIND DEAD ***\n";

    cout << "   Main Menu \n";
    cout << "1. Instructions\n"
         << "2. Begin\n"
         << "3. Exit\n";

    cout << "Enter Menu Selection: ";
    cin >> selection;

    while (selection < 1 || selection > 3)
    {
        cout << "You MUST choose an option between 1 and 3.\n"
             << "Enter Menu Selection: ";
        cin >> selection;
    }

    if (selection == 1)
        printMemory(gameArray, roomArray);
    else if (selection == 2)
        instructions();
    else if (selection == 3)
        return 0;
}

//pre: no preconditions
//post: displays the instructions to the player
void instructions()
{
    cout << "YOUR MISSION, SHOULD YOU CHOOSE TO ACCEPT IT, IS TO SEEK THE HOLY\n"
         << "GRAIL WITHIN THE RUINS OF AN ANCIENT CHURCH. TO SUCCEED YOU MUST\n"
         << "ENTER THE CHURCH, AVOID THE UNDEAD GUARDIANS, FIND THE GRAIL AND\n"
         << "ESCAPE. YOU HAVE SIX SILVER BULLETS TO PROTECT YOU. IF THE ZOMBIES\n"
         << "FIND YOU OR YOU RUN OUT OF BULLETS YOU WILL LOSE!\n";

}

void printMemory(int roomArray[][7])
{
    cout << "PrintMemory"; //stub for now
}


Last edited on
I'm having problems compiling my program. I've encountered this error:
The error is on line 97.

Actually the error is on line 163. Your function prototype, function implementation, and function call must all agree as to the type and number of arguments.


Also you should have several other errors:
In function 'int main()': 89:6: warning: unused variable 'menuSelection' [-Wunused-variable] In function 'bool menu(int&)': 122:20: warning: ISO C++ forbids zero-size array 'gameArray' [-Wpedantic] At global scope: 163:35: warning: unused parameter 'roomArray' [-Wunused-parameter] In function 'bool menu(int&)': 149:1: warning: control reaches end of non-void function [-Wreturn-type] 123:47: warning: array subscript is above array bounds [-Warray-bounds] /tmp/cckhg15X.o: In function `menu(int&)': :(.text+0x19c): undefined reference to `printMemory(int*, int (*) [7])' /tmp/cckhg15X.o: In function `main': :(.text.startup+0x5c): undefined reference to `menu(int&, int&, int&, int&, bool&, int*, int (*) [7])' collect2: error: ld returned 1 exit status
No I only have two errors.

|104|undefined reference to `menu(int&, int&, int&, int&, bool&, int*, int (*) [7])'|

|151|undefined reference to `printMemory(int*, int (*) [7])'|
||error: ld returned 1 exit status|
No I only have two errors.

These are linking errors. You have not defined the functions in question. You've defined versions of those functions that differ from your declarations, but the linker cannot find the definitions of the ones you've forward declared, as explained by jlb.
Topic archived. No new replies allowed.