Reputation: 4320
This is an error I had thought myself to be over, yet it's back at it, and I do not know why it's happening.
Here is the code from the .C file leading up to the error:
int main(int argc, char* argv[])
{
if( argc > 3 )
{
cout << "Too many arguments. Program will close.\n";
return 1;
}
else
{
int numRooms = 0;
int start = 0;
ifstream file;
if( argc == 3 )//Dump wanted
file.open( argv[ 2 ] , ifstream::in );
else
file.open( argv[ 1 ] , ifstream::in );
if( file.is_open() )
{
file >> numRooms;
Graph * maze = new Graph( numRooms );
The Graph * maze = new Graph( numRooms ); is where the error is being referenced (a11.C:41):
==17900== Use of uninitialised value of size 4
==17900== at 0x8048F05: Graph::Graph(int) (Graph.C:25)
==17900== by 0x8048C1D: main (a11.C:41)
From here we delve deeper, into the Graph.C file, lines 16 - 30:
Graph::Graph( int num )
{
numRooms = num;
_index = 0;
_start = 0;
easyDelete = new Room*[ num ];
escapePath = new string[ num ];
theWALL -> myNumber = -1;
theWALL -> visited = true;
safety -> myNumber = 0;
safety -> visited = false;
}
Line 25 is this: theWALL -> myNumber = -1;
"theWALL" and "safety" are both private *Room objects:
Private:
Room * theWALL;
Room * safety;
The struct "Room" looks like this:
struct Room
{
bool visited;
int myNumber;
Room *North;
Room *East;
Room *South;
Room *West;
};
It's initialized up when I call new Graph( numRooms ), and I am filling it it's information... yet I get this error.
Upvotes: 1
Views: 2449
Reputation: 9590
Looks like you are not allocating
Room * theWALL;
before using it at
theWALL -> myNumber = -1;
try something like
theWall = new Room();
theWALL -> myNumber = -1;
And you have the same bug for:
Room * safety;
try allocating that too.
Upvotes: 6