Basically, in the constructor, I want to pass through the characters of one array into those of another. I'm obviously not doing it properly since I get this error:
(22) : error C2440: '=' : cannot convert from 'char []' to 'char [10]'
(23) : error C2440: '=' : cannot convert from 'int []' to 'int [1][1]'
Here is my code:
Okay, another problem. I'm having trouble passing the array data through the function. When I try to run, I get a runtime error saying mainTempLocation is corrupt.
I'm forgetting how to use arrays properly today :S. I changed name into a string to save some trouble.
My new problem is that I need a way to return an array in an accessor function to view its contents. I looked it up and the only method I could find was returning a pointer to the array. This, for me, would defeat the purpose of using protected memberes, and probably wouldn't work anyway. What's the best way of creating an accessor for an array?
I found a couple other bugs in my code and made the changes you suggested. Here is the updated code if you need it.
You could either return it as a pointer to const data, or instead of returning it, copy it to a passed pointer.
Oh, and your memcpy() on line 25 is wrong. The third parameter should be 2*sizeof(int). I didn't mention that for the char array because sizeof(char)==1 is always true.
When I try to do this I have to create a local array for each function that needs to access the location array. Is this considered good programming practice? Also I'm not sure how to do it properly. Here's how I have it so far.
Player location accessor. int * GetLocation(){return location;}
In main:
1 2
int * player0Location[2];
player0Location=Player0.GetLocation();
This is the only way I can think of to do this but of course it gives me an error.
'=' : cannot convert from 'int *' to 'int *[2]'