473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

default parameter to NULL


I have a method with the last arguments having defaults like this

void filing(long, double,
const myType& r_mo=NULL,
const herType& r_tr=NULL);

is that acceptable, if not how is it done?
when I do the above, I get errors like

file.h:19: error: default argument for parameter of type ‘const myType&’ has type ‘int’
file.h:20: error: default argument for parameter of type ‘const herType&’ has type ‘int’
Dec 21 '06 #1
3 8742
"Gary Wessle" <ph****@yahoo.comwrote in message
news:m3************@localhost.localdomain...
>
I have a method with the last arguments having defaults like this

void filing(long, double,
const myType& r_mo=NULL,
const herType& r_tr=NULL);

is that acceptable, if not how is it done?
when I do the above, I get errors like

file.h:19: error: default argument for parameter of type 'const myType&'
has type 'int'
file.h:20: error: default argument for parameter of type 'const herType&'
has type 'int'
A reference can't have a NULL value, one reason being becasue you can't
check for it. You can do that with a pointer, but not a reference.
Dec 21 '06 #2
Gary Wessle wrote:
I have a method with the last arguments having defaults like this

void filing(long, double,
const myType& r_mo=NULL,
const herType& r_tr=NULL);

is that acceptable, if not how is it done?
when I do the above, I get errors like
No, it is not reasonable to attempt to pass NULL for any parameter
declared a reference - a reference requires that the caller always
supply an object (of a suitable type) in order to call the function.

To indicate that values for myType and herType are not required in
order to call filing(), there are a few options available. One approach
is for filing to accept pointers instead of references for those
values:

void filing( long, double,
const myType* r_mo = NULL,
const herType* r_tr = NULL);

A better approach would probably be to overload filing() - with one
overload accepting the two reference parameters and another overload of
filing() that does not:

void filing( long, double, const myType& r_mo, const herType&);
void filing( long, double);

Greg

Dec 21 '06 #3

"Greg дµÀ£º
"
Gary Wessle wrote:
I have a method with the last arguments having defaults like this

void filing(long, double,
const myType& r_mo=NULL,
const herType& r_tr=NULL);

is that acceptable, if not how is it done?
when I do the above, I get errors like

No, it is not reasonable to attempt to pass NULL for any parameter
declared a reference - a reference requires that the caller always
supply an object (of a suitable type) in order to call the function.

To indicate that values for myType and herType are not required in
order to call filing(), there are a few options available. One approach
is for filing to accept pointers instead of references for those
values:

void filing( long, double,
const myType* r_mo = NULL,
const herType* r_tr = NULL);

A better approach would probably be to overload filing() - with one
overload accepting the two reference parameters and another overload of
filing() that does not:

void filing( long, double, const myType& r_mo, const herType&);
void filing( long, double);

Greg
I agree with you.

Dec 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike | last post by:
If possible, how do I use a function to create a default parameter value? The following gives me an "unexpected '(', expecting ')'" error, which makes sense. function DisplayInfo($ID,...
26
by: Alex Panayotopoulos | last post by:
Hello all, Maybe I'm being foolish, but I just don't understand why the following code behaves as it does: - = - = - = - class listHolder: def __init__( self, myList= ): self.myList =...
49
by: Mark Hahn | last post by:
As we are addressing the "warts" in Python to be fixed in Prothon, we have come upon the mutable default parameter problem. For those unfamiliar with the problem, it can be seen in this Prothon...
12
by: earl | last post by:
class temp { public: temp(); foo(char, char, char*); private: char matrix; }; temp::foo(char p, char o, char m = matrix )
2
by: Patrick Kowalzick | last post by:
Dear all, Is the default parameter for t in the function foo guaranteed to be NULL in the case below ? (MSVC 7.1 and g++ implements it like that) #include <iostream> template <typename T>...
11
by: Matthias Pfeifer | last post by:
Hi there, I am trying to declare a function that takes a std::list<parameter. I want this function to have an empty list as a default parameter. It's a template function also. Currently i am...
6
by: s0suk3 | last post by:
I wanted to know if there's any way to create a method that takes a default parameter, and that parameter's default value is the return value of another method of the same class. For example: ...
1
by: s0suk3 | last post by:
I had posted this before but all the spam whipped it out... I wanted to know if there's any way to create a method that takes a default parameter, and that parameter's default value is the return...
2
by: manontheedge | last post by:
I'm trying to pass a pointer of a class into another class' constructor. I keep getting the error "missing default parameter", here's a hopefully simplified example of what I'm trying to do... ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.