Jump to content
  • Advertisement
Sign in to follow this  
Protocol_0

Vectors Arrays In Classes

This topic is 4706 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

How do you use vector arrays in classes? I've been trying for about an hour, and could never figure out how to declare one in the declaration section, then how to assign it values in the assignment section. It's frustrating. I know how to use them in a program that doesn't uses classes, though.

Share this post


Link to post
Share on other sites
Advertisement
It's no different from declaring any other variable in a class.


class A
{
public:
//interface
private:
std::vector</*insert type here*/> data;
};

Share this post


Link to post
Share on other sites
Hey,

Right then, some source code


#include <vector>

class AddToVector
{
public:
void Add( int item )
{
collectionOfIntegers.push_back( item );
}


private:
std::vector< int > collectionOfIntegers;
};




Ok.

So i put the method code inside the class definition for compactness, it isnt necessary.

Hope this helps.

ace

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!