Vector inside structure pointer

Hi, everybody.

1
2
3
4
5
6
7
8
9
10
11
12
13
struct activity{
int id; //Activity number};

vector<activity> activity(32);

activity *p_id; //Declare a pointer
vector<int> *p_activity; //Declare a pointer

for(int i=0; i<32;i++)
{
activity[i].id=i+1;
}


I want to make assingments in for loop by using pointers to be faster.
I declared the pointers but I couldn't use them in a correct way.

1
2
3
4
for(int i=0; i<32;i++)
{
Assign values by using pointers;
}


Thanks.

Last edited on
What do you want to do with pointers? I don't see any sensible way to use them here.
Last edited on
I just want to use pointer in a loop while assignning values.

Because, actually my vector size is very big and it takes time. So, I want to use adresses.
In a vector of N elements you will have to do N integer assignments. There is nothing you can gain here form using pointers.
So, when the pointers are faster to use ?

Actually I want to access to a vector which is inside structure. So, one I got the adress I will use that adress in the future. Is it correct ?
Last edited on
You use pointers either when you're dealing with dynamic memory or when you want to avoid copying (though for the 2'nd one you should use references).
Once again, there is nothing to gain here. Think about your algorithm. Does it involve any unnecessary copies?
ok thank you very much ;)
Topic archived. No new replies allowed.