Sign in to follow this  
Deek880

How do I instantiate a pointer to a vector?

Recommended Posts

vector<int> * Case=0; Case->resize(4); Case[0]=1; Case[1]=0; Case[2]=0; Case[3]=0; I am getting the following error: C:\Program Files\Microsoft Visual Studio\MyProjects\DealorNo\main.cpp(58) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion) How do i initialize a pointer to vector element?

Share this post


Link to post
Share on other sites
first line should read:

vector<int> * Case = new vector<int>;

but are you sure you want to do this? :)

You probably just want to do vector<int> Case;

Share this post


Link to post
Share on other sites

std::vector<int>* Case = new std::vector<int>(4);
(*Case)[0] = 1;
// ...
delete Case;

But you probably want

std::vector<int> Case(4);
Case[0] = 1;

Share this post


Link to post
Share on other sites
I'm trying to call a function with a vector at runtime that use the rand ()
standard cstdlib.

I want to call it several times with a different seed value to get a new value each time it is called. I believe it's not working because the seed value is being generated at compile time instead of run time. I'm trying to see wether I can resolve this with pointers

Share this post


Link to post
Share on other sites
You should only make one call to srand() at the beginning of your program. You shouldn't call it again after that. The random generator maintains an internal state, and each time you call srand() it resets that internal state. Just let it do its business and maintain its own state and only call srand() once.

Using pointers will not fix this. It's not a matter of things being determined at compile time vs runtime. You shouldn't call srand() more than once.

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