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 4 9092
<ja****@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
| 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 ja****@gmail.com wrote: 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.
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 ja****@gmail.com wrote: 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?). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Frank Bechmann |
last post by:
Eventually most of you will not learn much from this because it's just
another event in the 'default argument value gotcha' series, but
because it cost me some hours yesterday to spot this 'error'...
|
by: Alex Vinokur |
last post by:
Various forms of argument passing
=================================
C/C++ Performance Tests
=======================
Using C/C++ Program Perfometer...
|
by: Dave Vandervies |
last post by:
If I feed this to g++:
--------
int foo(int i=42);
int foo(int i=42)
{
return i;
}
--------
It says (with -W -Wall -ansi -pedantic):
|
by: Dan Cernat |
last post by:
Hi there,
A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they...
|
by: gregory.petrosyan |
last post by:
Hello everybody!
I have little problem:
class A:
def __init__(self, n):
self.data = n
def f(self, x = ????)
print x
All I want is to make self.data the default argument for self.f(). (I
|
by: Edward Diener |
last post by:
Given
value class X
{
public:
// Not allowed: X():i(100000),s(10000) { }
// Allowed
void InitializeDefaults() { i = 100000; s = 10000; }
private:
int i;
|
by: n.torrey.pines |
last post by:
std::pair explicitly defines a default constructor. This makes it
impossible to instantiate it with a type that does not have a default
constructor (or it is private).
I wonder if it would be...
|
by: Jess |
last post by:
Hello,
I tried several books to find out the details of object
initialization. Unfortunately, I'm still confused by two specific
concepts, namely default-initialization and...
|
by: JohnQ |
last post by:
Are a default constructor, destructor, copy constructor and assignment
operator generated by the compiler for a struct if they are not explicitely
defined?
I think the answer is yes, because...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |