Sign in to follow this  

vector member assignation

Recommended Posts

The correct term is assignment, but I do like assignation now that you've coined it ;)

The way you've written it at the moment you'll have to create one, and then copy it into the struct like this:
//create a point
POINT temp;
temp.x = 42;
temp.y = 73;
temp.z = 12;
myvector.push_back( temp );
//modify it
myvector.back().x = 43;
myvector.back().y = 74;
myvector.back().z = 13;

The alternative is to create a constructor:
struct POINT {
POINT( int x, int y, int z ) : x(x), y(y), z(z) {}
int x,y,z;
//create a point
myvector.push_back( POINT(42, 73, 12) );
//edit it
myvector.back() = POINT(43, 74, 13);

Share this post

Link to post
Share on other sites
Well, the vector gives you random access (access to any random member using square brackets []) and iterator access (access through an iterator). Neither seems to be significantly more efficient at accessing data.

You can push_back a ton of POINTs and use one of the two about to assign them.
ex: size_t i;                    vector[i++] = POINT(1,2,3);
ex: vector< POINT>::iterator it; (*it)++ = POINT(1,2,3);

you can learn more here:

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this