SOLVED! Small C++ array assignment prob
Hi,
This is a very tiny C++ problem.
I have an array I want to assign several integers. I could do it like this:
int animWalk[12] = { 2, 3, 4, 5, 4, 3, 2, 6, 7, 8, 7, 6 };
Trouble is, the array is actually a member of an object. I've got this in my .h file:
int m_AnimWalk[12];
But when I try to fill the array with ints like this:
m_AnimWalk[12] = { 2, 3, 4, 5, 4, 3, 2, 6, 7, 8, 7, 6 };
or this
m_AnimWalk[] = { 2, 3, 4, 5, 4, 3, 2, 6, 7, 8, 7, 6 };
I get a syntax error.
I've had to do it this way:
m_AnimWalk[0] = 2;
m_AnimWalk[1] = 3;
m_AnimWalk[2] = 4;
m_AnimWalk[3] = 5;
(etc....)
Is there an easier way? I definitely want an array, not a vector. These values will never change in my program.
[Edited by - darenking on July 18, 2005 7:05:57 AM]
you could make the array static so you can initialize it (has to be somewhere outside of the class)
/* foo.hpp */class Foo {static int m_AnimWalk[12];};/* foo.cpp */int Foo:m_animWalk[] = {1,2,3,4,5};
I think you can only initialize multiple values of an array when defining it...
As Gink said, why not initialize in your header?
Cheers
Eric
As Gink said, why not initialize in your header?
Cheers
Eric
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement