URGENT-"Undefined Reference to 'Stack::Pop()'" when compiling

I finally figured out the code and everything for a mouse maze but when I go to compile my seperated program4.cc file and my Maze.cc file together, it returns with this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
program4.o: In function `WalkThroughMaze(Maze&, int, int)':
program4.cc:(.text+0xbf): undefined reference to `Stack::Push(DATA)'
program4.cc:(.text+0xe2): undefined reference to `Stack::StackTop(DATA&)'
program4.cc:(.text+0xfb): undefined reference to `Stack::Pop(DATA&)'
program4.cc:(.text+0x108): undefined reference to `Stack::Pop(DATA&)'
program4.cc:(.text+0x114): undefined reference to `Stack::Push(DATA)'
program4.cc:(.text+0x198): undefined reference to `Stack::Push(DATA)'
program4.cc:(.text+0x1df): undefined reference to `Stack::Push(DATA)'
program4.cc:(.text+0x1ec): undefined reference to `Stack::Pop(DATA&)'
program4.cc:(.text+0x249): undefined reference to `Stack::Push(DATA)'
program4.cc:(.text+0x264): undefined reference to `Stack::Pop(DATA&)'
program4.cc:(.text+0x2ae): undefined reference to `Stack::IsEmpty()'
program4.cc:(.text+0x2e0): undefined reference to `Stack::IsEmpty()'
program4.cc:(.text+0x340): undefined reference to `Stack::~Stack()'
program4.cc:(.text+0x367): undefined reference to `Stack::~Stack()'
program4.cc:(.text+0x383): undefined reference to `Stack::~Stack()'
program4.cc:(.text+0x3b4): undefined reference to `Stack::~Stack()'
program4.o: In function `main':
program4.cc:(.text+0x505): undefined reference to `Maze::Maze()'
collect2: ld returned 1 exit status 


Here is my program4.cc file:

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
#include <cstdlib>
#include <iomanip>
#include <string>
#include <iostream>
#include <fstream>
#include "Boolean.h"
#include "Stack.h"
#include "Maze.h"

using namespace std;

void Menu(Maze&);
void WalkThroughMaze(Maze&, int, int);
bool CheckExit(int, int);

int main(){
   Maze maze;
   maze.FillMatrix();
   Menu(maze);
   return 0;
}

void Menu(Maze &maze){
   int start, exit, option;
   bool cont = true;
   while(cont){
      cout<<"Welcome to Mouse in a Maze: \n"<<endl;
      cout<<"Please select an option: \n";
      cout<<"1) Begin Mouse in Maze game. \n";
      cout<<"2) Exit program. \n";
      cin>>option;
      if (option = 1){
         cout<<"Please enter desired starting point for the mouse -> \n";
         cin>>start;
         cout<<"Now enter desired exit point for the maze -> \n";
         cin>>exit;
         cout<<endl;
         cout<<"Mouse going through maze: \n";
         WalkThroughMaze(maze, start, exit);
         cont = true;
      }
      else if (option = 0)
         cont = false;
      else{
         cout<<"Incorrect input for option -- Try again \n";
         cont = true;
      }
   }
}


void WalkThroughMaze (Maze &maze, int start, int exit){
   Stack visitStack, backStack;
   DATA mouse, next, decision;
   bool exitFlag;
   decision.row = -1; //Set the decision marker
   mouse.row = start;
   int k, j, i; //Counters used in walkthrough
   visitStack.Push(mouse);
   //Check to see if start position is the exit
   exitFlag = CheckExit(mouse.row, exit);
   while(!exitFlag AND !visitStack.IsEmpty()){
      visitStack.StackTop(mouse); //Get top of the list value
      if(mouse.row EQ -1){
         //If the top of the visitStack is the decision
         //marker, delete decision marker and go to that
         //position received from backStack
         visitStack.Pop(mouse);
         backStack.Pop(mouse);
         visitStack.Push(mouse);
         maze.MarkVisited(mouse.row);
         cout<<"*"<<mouse.row<<endl;
         if(CheckExit(mouse.row, exit))
            exitFlag = true;
      }
      else{
         //Set counters to 0
         k = 0;
         j = 0;
         while(maze.Neighbor(mouse.row, j)){
            //Count the number of neighbors and
            //push neighbors to backStack
            next.row = j;
            backStack.Push(next);
            k++;
            j++;
         }
         if(k = 1){
            //If there is only one neighbor, move mouse
            //to next position
            mouse = next;
            visitStack.Push(mouse);
            backStack.Pop(mouse);
            maze.MarkVisited(mouse.row);
            cout<<mouse.row<<endl;
            if(CheckExit(mouse.row, exit))
               exitFlag = true;
         }
         else if (k GT 1){
            //If there is more than one neighbor, push -1
            //to visitStack
            i = 0;
            while(i LT k){
               visitStack.Push(decision);
               i++;
            }
         }
         else{
            //Position is not exit nor does it have neighbors
            visitStack.Pop(mouse);
            cout<<"*"<<mouse.row<<endl;
         }
      }
   }
   if(visitStack.IsEmpty()){
      //Stack is empty and no exit was found
      cout<<"No exit found, reward mouse with cheese anyway\n";
   }
   else{
      //Exit has been found
      cout<<"Mouse has found exit at position("<<mouse.row<<").\n";
      cout<<"Reward mouse with cheese!\n";
   }
}

bool CheckExit(int position, int exit){
   bool success;
   if (position EQ exit){
      success = true;
   }
   else{
      success = false;
   }
   return success;
}


And here is my Maze.cc file:

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
#include "Maze.h"
#include "Boolean.h"
#include <cstdlib>
#include <iomanip>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

Maze::~Maze(){
   delete []maze;
   delete []visitArray;
}

void Maze::FillMatrix(){
   int i = 0; //Counter for rows
   int j = 0; //Counter for columns
   ifstream infile;
   infile.open("Matrix.data"); //Opens Matrix.data
   if (infile.fail()){
      cout<<"Could not read file. \n";
      exit (1);
   }
   infile>>maze[i][0];
   while(!infile.eof()){
      for (i = 0; i LT size; i++){
         for (j = 1; j LT size; j++)
            infile>>maze[i][j];
         infile>>maze[i+1][0];
      }
   }
   infile.close(); //Close file
}

bool Maze::CheckVisited(const int &i){
   bool success;
   if (visitArray[i] != 0)
      success = true;
   else
      success = false;
   return success;
}

bool Maze::MarkVisited(const int &i){
   bool success;
   if (CheckVisited(i)){
      //print error
      success = false;
   }
   else{
      visitArray[i] = 1;
      success = true;
   }
   return success;
}

bool Maze::Neighbor(const int &i, int &j){
   bool success = false;
   while(j LT size AND !success){
      if(maze[i][j] = 1 AND !CheckVisited(j))
         success = true;
      else{
         success = false;
         j++;
      }
   }
   return success;
}


Any help? I can't figure out my compiling problem and this code is due tomorrow. Also, my code is probably not completely correct for output but I will work out the dinks later when I am able to compile it.
Did you actually define and compile the functions to your stack class? (and your maze class' constructor?)
Last edited on
I forogot that I had the third .cc file to compile for my Stack methods. Being rushed for the deadline and I completely forgot about including them in with my compile. Thanks for reminding me!
Topic archived. No new replies allowed.