Private Struct and Template Class

I am having trouble understanding how to access the struct. This is exactly how this part of the code is supposed to look according to the assignments but i feel like it is not 100% correct. The Read member seems to be getting errors.

I tried doing this in the main in order to have an array of 6 intergers and have it displayed using the persons name.

Such as "John this is your array": 1 2 3 4 5 6
But it didn't work. The struct within the private is really confusing me. Any help would be appreciated.

1
2
SIX<int, 6> J;
J.Read;


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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
template<class T, int n>
class SIX {
private:
	struct BOX{
		T a[n];
		string Name;
	};
public: 
	void Read()
	{
		cout<<"Enter your name:";
		cin>>Name;
		cout<<Name<<"Please enter"<<n<<" data:";
		for (int i=0; i<n; ++i)
			cin>>a[i];		
	}
	void SortArray(){
		sort(a, a+n);
	}
	void Display(){
		cout<<Name<<"this is the sorted list of data in your array a\n";
		for(int i=0;i<n;++i)
			cout<<a[i]<<"\t";
		cout<<endl;
	}
};
int main()
{
	
}
You have only defined BOX struct. You need to create an instance in your class.

1
2
3
4
5
6
7
8
9
10
11
12
13
private:
	struct BOX{
		T a[n];
		string Name;
	};
	BOX data;
public: 

//...
//Access:
data.a[x];
/*or*/
this->data.a[x];
Thanks alot MiinIPaa. Managed to get it to compile with your help.
Topic archived. No new replies allowed.