SRO problem for nested operator

Can Anyone help me out for the following

class game
{
private:
struct player
{
struct coins
{
int location[20][20];
}coin[4];
}p[4];
}l;


i want to declare the int array location[][] for coin[1] in p[1] for game l by using Scope Resolution Operator. Please someone tell me the syntax of this.If there is no way to declare this by SRO then plz suggest me sum other way.... =D
In general it's not worth trying to use [] in this way. You always have to use patterns/tricks that are tricky to extend.

Having said that, here's something you can play around with, but I wouldn't put this sort of thing in a program just for the sake of using operator[].
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
#include <iostream>
#include <stddef.h>

struct info
{
};

template <typename T, size_t N = 5>
class array
{
	T _a[N];
public:
	T& operator[](size_t idx) { return _a[idx]; }

	size_t size() const { return N; }
};

int main()
{
	typedef array<info, 100> infoarray;
	infoarray a;
	info x = a[0];

	typedef array<infoarray, 1000> infoarray2d;
	infoarray2d a2d;
	x = a2d[0][0];

	std::cout << a2d.size() << 'x' << a2d[0].size() << std::endl;

	return 0;
}
Last edited on
sir,can u plz give a simple explaination about the above program....I'm just a beginner....
Topic archived. No new replies allowed.