private-public members:S

when i try this code it gives several errors:S i did all of declarations in public but again i take these errors; i did public to node but i didnt work

Error	2	error C2248: 'SimSpace<T>::node' : cannot access private member declared in class 'SimSpace<T>
Error	3	error C2248: 'SimNode<T>::link' : cannot access private member declared in class 'SimNode<T>'
Warning	1	warning C4101: 'x' : unreferenced local variable



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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include<iostream>

using namespace std;

template<class T>
class SimSpace;

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;
}
////////////////////////////////////////////////////////////////////////////////
template<class T>
class SimChain 
{
public:
	SimChain(){first= -1;}
	~SimChain(){Destroy();}
	void Destroy();
	int Length()const;
	bool Find(int k, T& x)const;
	int Search(const T& x)const;
	SimChain<T>& Delete(int k, T& x);
	SimChain<T>& Insert(int k,const T& x);
	void Output(ostream& out)const;
private:
	int first;
	static SimSpace<T> S;
};

template<class T>
void SimChain<T>::Destroy()
{
	int next;
	while(first!=-1)
	{
		next = S.node[first].link;
		S.Deallocate(first);
		first = next;
	}
}

template<class T>
int SimChain<T>::Length()const
{
	int current = first;
	int len =0;
	while(current!= -1)
	{
		current = S.node[current].link;
		len++;
	}
	return len;
}

template <class T>
bool SimChain<T>::Find(int k,T& x)const
{
	if(k<1) return false;
	int current= first;
	int index= 1;
	while(index<k && current!= -1)
	{
		current= S.node[current].link;
		index++;
	}
	if(current!=-1)
	{
		x = S.node[current].data;
		return true;
	}
	return false;
}

template<class T>
SimChain<T>& SimChain<T>::Delete(int k,T& x)
{
	if(k<1 || first == -1)
		throw OutOfBounds();
int p = first;

if(k==1)
	first = S.node[first].link;
else
{
	int q=first;
	for(int index=1 ; index< k-1 && q!=-1;index++)
		q= S.node[q].link;
	if(q== -1 ||S.node[q].link == -1 )
		throw OutOfBounds();
	p= S.node[q].link;

	S.node[q].link = S.node[p].link;
}

x= S.node[p].data;
S.Deallocate(p);
return *this;
}

template<class T>
SimChain<T>& SimChain<T>::Insert(int k,const T& x)
{
	if(k<0) throw OutOfBounds();
	int p = first;
	for(int index=1; index < k && p!= -1 ; index++)
		p= S.node[p].link;

	if(k>0 && p==-1)
		throw OutOfBounds();
	int y = S.Allocate();
	S.node[y].data = x;

	if(k)
	{
		S.node[y].link = S.node[p].link;
		S.node[p].link = y;
	}
	else
	{
		S.node[y].link = first;
		first = y;
	}
	return *this;
}

////////////////////////////////////////////////
void main(void)
{
	int x;
	SimChain<int> c;

}
Topic archived. No new replies allowed.