Thanks for your help guys. I have found though that it isn't whether it is possible to access the variables that is the problem. I have never had an explanation for the problem and if anyone could explain or even better point me to a tutorial that does explain it, that would be great. OK, basically I have some classes for my battleships game, one for each type of ship. They are some thing like this:
Code:
class tug{
int nopos 2; //number of map positions it uses
int arraypos[2]; //integer values of grid positions
//other data members
}usertug, cputug;
class sub{
int nopos 3; //number of map positions it uses
int arraypos[3]; //integer values of grid positions
//other data members
}usersub, cpusub;
//etc....
I then created a template function for ship placement so that I could pass any of my ships into it to be positioned on the grid.
The function was:
Code:
template <class T>
T placeship(T aship....etc..)
{
//code to place ship
}
However, within the template function, I found that although when I used for example aship.nopos, and passed in usersub, the value was correctly 3. But when I tried to for example write aship.arraypos[0]=value, the value was never put into the array.
Any help on this topic would be gratefully received as I have not found it in any tutorials and it has not been taught to us at university.