Run Time Error with Pointers and Structs..

So I'm trying to create a struct that contains a single int data member, and separate from the struct I am trying to create two global functions, each of which takes a pointer to the struct. I want the first function to contain a second int argument and sets the struct's int to the argument value, while the second function displays the int from struct.

The code that I have is provided below. When I Build it I don't receive any error or warnings. However, when I try to run the program I get an error:

Debug Error!
Run-Time Check Failure #3 - The variable 'call' is being used without being initialized.


Now, I thought I was initializing 'call'... but I guess I'm going about it the wrong way. Any help would be great.

Here is my Test.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef STRUCT_PTR_H
#define STRUCT_PTR_H

struct Structure1
{
public:
	int dataMem;
};

void globFunc1(Structure1* call, int arg1);
int globFunc1(Structure1* call);

#endif //STRUCT_PTR_H 


Here is Test.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <iostream>
#include "Test.h"
using namespace std;

void globFunc1(Structure1* call, int arg1)
{
	call->dataMem = arg1;
}

int globFunc1(Structure1* call)
{
	return call->dataMem;
}


And mainTest.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <iostream>
#include "Test.h"
using namespace std;


int main()
{
	int x = 5;
	Structure1* call;
	globFunc1(call, x);
	printf("%d\n", globFunc1(call));
}


Thanks to all who take a look!
call is pointing at a random position, not to a Structure1 object.
If you want to create an object initialize it this way:
1
2
3
4
5
Structure1* call = new Structure1; // create an object

// do your stuff with call

delete call; // release memory 
Perfect, works great!
Thanks Bazzy. I'm going to go look more info up on new. I've never heard of it before.
If you need it, here is a good tutorial: http://www.cplusplus.com/doc/tutorial/dynamic/
Topic archived. No new replies allowed.