default argument value for vector

J

jagrat

Hi all,

I have a function declaration as:

func(int somex = 0, int somey = 0, int* someval = NULL, vector<int>
v_Val)

compiler gives me error that last argument is without its default
argument.

I have tried various possible combination to assign some default value
to the vector but somehow compiler is not accepting it.

I know NULL, or (1), or vector<int>(1), or new vector<int>(1) will not
work.

Can anyone please let me know what should be the value I have to supply
as the default argument to the parameter.

Thanks,
Jag
 
C

Chris \( Val \)

| Hi all,
|
| I have a function declaration as:
|
| func(int somex = 0, int somey = 0, int* someval = NULL, vector<int>
| v_Val)
|
| compiler gives me error that last argument is without its default
| argument.
|
| I have tried various possible combination to assign some default value
| to the vector but somehow compiler is not accepting it.
|
| I know NULL, or (1), or vector<int>(1), or new vector<int>(1) will not
| work.
|
| Can anyone please let me know what should be the value I have to supply
| as the default argument to the parameter.

v_Val = std::vector<int>()

Cheers,
Chris Val
 
R

Ron Natalie

I know NULL, or (1), or vector<int>(1), or new vector<int>(1) will not
work.
void func(vecto<int> v_val = vector<int>(1));
should work fine. NULL and 1 aren't things you can initialize vectors
with. new vector returns a pointer which is similarly wrong.

vector<int>(0) or even vector<int>(1) will also work.
 
J

jagrat

Thanks all,

Even after writing vector<int>(1), I was getting error about syntax
error in the declaration. I believed that it is due to vector but I
figured the error was due to other problems.

Thanks, have a great day!!!
Jag
 
R

Ron Natalie

Thanks all,

Even after writing vector<int>(1), I was getting error about syntax
error in the declaration. I believed that it is due to vector but I
figured the error was due to other problems.

How about posting verbatim what you tried. Is vector a known type?
(Did you include <vector> and use the appropriate namespace access?).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top