(In the header)
float m_pfStateActionValueTable[NUM_STATES][NUM_ACTIONS];
(In the source)
void TermiteBrain::setStateActionValueTable (float** fStateActionValueTable){
m_pfStateActionValueTable = fStateActionValueTable;
}
Passing arrays to a function
I have a static array in a class and I want to be able to change the reference so that it points to another array passed via a function, i.e. so that several instances of a class can operate on the same array.
I get the error:
error C2440: '=' : cannot convert from 'float ** ' to 'float [1024][14]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
What am I doing wrong?
I'd rather not store the array as dynamic, but if thats the only way then I suppose I'll have to.
Have you considered using memcpy?
When you declare
float m_pfStateActionValueTable[NUM_STATES][NUM_ACTIONS];
you're allocating that memory block of the size you requested. Really if you want to change your global variable to point to some array, you need to make it a pointer in the first place, or you need to copy it in, but you really shouldn't take a non-pointer-declared variable like that and rip it away from the memory it was originally allocated to. C won't let you do that very easily for your own safety.
-fel
When you declare
float m_pfStateActionValueTable[NUM_STATES][NUM_ACTIONS];
you're allocating that memory block of the size you requested. Really if you want to change your global variable to point to some array, you need to make it a pointer in the first place, or you need to copy it in, but you really shouldn't take a non-pointer-declared variable like that and rip it away from the memory it was originally allocated to. C won't let you do that very easily for your own safety.
-fel
Ah, you misunderstand, I dont want to copy the array, I want several objects to be able to operate on the same array, so I need a reference rather than a copy.
Quote:Original post by DangerDave
Ah, you misunderstand, I dont want to copy the array, I want several objects to be able to operate on the same array, so I need a reference rather than a copy.
well you can't make the name of a static array refer to a different array.
I understand what you want to do. I just think that's a bad idea given your declaration of m_pfStateActionValueTable. I went ahead and edited an explanation of that in my original reply (prior to your comment).
-fel
-fel
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement