Jump to content
  • Advertisement
Sign in to follow this  
darenking

SOLVED! Small C++ array assignment prob

This topic is 4875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
Why not just initialize it in the header file if it isnt going to change at all?

Share this post


Link to post
Share on other sites
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};

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!