Friend Class(question)

i want to use friend class but when i try i take these errors pls help me:S i am sure i am not using frien function correctly but didnt solved:(

Error	1	error C2143: syntax error : missing ';' before '<'	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	8
Error	2	error C2433: 'SimSpace' : 'friend' not permitted on data declarations	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	8
Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	8
Error	4	error C2238: unexpected token(s) preceding ';'	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	8
Error	5	error C2143: syntax error : missing ';' before '<'	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	29
Error	6	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	29
Error	7	error C2086: 'int SimSpace' : redefinition	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	29
Error	8	error C2988: unrecognizable template declaration/definition	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	29
Error	9	error C2059: syntax error : '<'	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	29
Error	10	error C2039: 'Allocate' : is not a member of '`global namespace''	c:\users\tess\documents\visual studio 2010\projects\deneme\deneme\simspace.h	40
Error	11	error C2143: syntax error : missing ';' before '{'	41
Error	12	error C2447: '{' : missing function header (old-style formal 
Error	13	error C2143: syntax error : missing ';' before '<'	
Error	14	error C2182: 'SimSpace' : illegal use of type 'void'	
Error	15	error C2086: 'int SimSpace' : redefinition	
Error	16	error C2988: unrecognizable template declaration/definition	
Error	17	error C2059: syntax error : '<'	
Error	18	error C2039: 'Deallocate' : is not a member of '`global namespace'





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
#include <iostream>
using namespace std;

template<class T>
class SimNode
{
	friend SimSpace<T>;
private:
	T data;
	int link;
};

template<class T>
class SimSpace
{
public:
	SimSpace(int MaxSpaceSize=100);
	~SimSpace(){delete[]node;}
	int Allocate();
	void Deallocate(int& i);
private:
	int NumberOfNodes;
	int first;
	SimNode<T> *node;
};

template <class T>
SimSpace<T>::SimSpace(int MaxSpaceSize)
{
	NumberOfNodes = MaxSpaceSize;
	node = new SimNode<T> [NumberOfNodes];
	for(int i=0; i<NumberOfNOdes-1; i++)
		node[i].link = i+1;
	node[NumberOfNodes-1].link = -1;
	first = 0;
}

template<class T>
int SimSpace<T>::Allocate()
{
	if(first == -1) throw NoMem();
	int i= first;
	first = node[i].link;
	return i;
}

template<class T>
void SimSpace<T>:: Deallocate(int& i)
{
	node[i].link = first;
	first = i;
	i= -1;
}
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
//...
template <class T>
class SimSpace;

template<class T>
class SimNode
{
	friend class SimSpace<T>;
private:
	T data;
	int link;
};
//... 
thanks it works ;)
Topic archived. No new replies allowed.