trying out fork() and wait(), compiler seems to forget what dereferencing is

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
#include <stdlib.h>
	//recommended headers for wait(), if CC says wait not defined, try these:
//	#include <sys/types.h>
//	#include <sys/stat.h>
#include<iostream>
using namespace std;

int main()
{
	int array[4];
	
	int id;
	int *res;
	int ret;
	
	for (int count = 0; count < 4 ; count++)
	{
		array[count] = count*100;
	}
	
	id  = fork();
	
	if (id == 0)
	{
		cout << "kid" << endl;
		return 99;
	}
	
	else
	{
		wait(res);
		ret = ( *res);
		cout << res;
		cout << ret;
	}
	
	return 0;
}


That's a small program I wrote to get a feel for fork() and wait(), but I've ended up with a ridiculous compiler error:

forker.cpp:37: error: no match for ‘operator*’ in ‘*res’
forker.cpp:38: error: no match for ‘operator<<’ in ‘std::cout << res’
forker.cpp:13: warning: unused variable ‘res’


the first error seems to say that it doesn't know what the dereference operator does. I thought that I could be passing wait() an incorrect type, but my notes and the error messages don't seem to say that anything is wrong with that.

I also know that some of the code doesn't really amount to any result, but this is just a small incomplete program for trying out syntax.
wait is undeclared (which is not at all what the compiler is saying, but comment out line 31 and watch it compile cleanly).

Then include

1
2
#include <sys/types.h>
#include <sys/wait.h> 
Topic archived. No new replies allowed.