473,387 Members | 1,766 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,387 software developers and data experts.

enter default values instead of passing to Function

Default arguments are those arguments that are substituted for the missing arguments in the function call. Is it possible to enter default values, instead of providing them in the function prototype / function header?
Help me
May 1 '07 #1
1 1128
JosAH
11,448 Expert 8TB
Default arguments are those arguments that are substituted for the missing arguments in the function call. Is it possible to enter default values, instead of providing them in the function prototype / function header?
Help me
If you don't mind using some pointers:
Expand|Select|Wrap|Line Numbers
  1. int def_p= 42; // the "default default"
  2.  
  3. void f(int* p= &def_p) { // function with a default parameter
  4.    cout << *p << endl;
  5. }
  6.  
  7. void set_def_p(int val= 0) { def_p= val; } // change the default
  8.  
  9. int main() {
  10.  
  11.    set_def_p(54);
  12.    f();
  13. }
kind regards,

Jos
May 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
5
by: Eric | last post by:
Hi All, I'm very experienced in traditional ASP and am new to (am learning) ASP.NET. FYI: I am initially learning ASP.NET with VB.NET to ease the transition for me. I have encountered what I...
2
by: Urs van Binsbergen | last post by:
Hi! This sounds probably quite silly, but I just can't figure out this one. Consider the following which lets "a" be an array with 0 elements: Dim a() As Integer a = New Integer() {} Now...
4
by: Steven D'Aprano | last post by:
I'm having problems passing a default value to the maxsplit argument of str.split. I'm trying to write a function which acts as a wrapper to split, something like this: def mysplit(S, sep=None,...
10
by: Alan G Isaac | last post by:
My class MyClass reuses many default parameters with a small number of changes in each instance. For various reasons I decided to put all the parameters in a separate Params class, instances of...
12
by: Daniel Klein | last post by:
I'm pretty new at php and web stuff so please be gentle with me. I'm trying to get a form to submit when the user presses the Enter key. I do not want to use javascript. I've googled this to...
7
by: George Sakkis | last post by:
A situation that often comes up is having to initialize several instance attributes that accept a default value. For a single class, passing the default values in __init__ is fine: class...
6
by: Mark B | last post by:
I have a function that looks up a SQL table to see if a search term matches. It works fine but so far there are two things yet to work: 1) After entering a search term and pressing Enter, nothing...
43
by: kenneth | last post by:
Dear all, I have encountered this weird problem. I have a class definition with an __init__ argument 'd' which defaults to {}. This argument is put in the 'self.d' attribute at initialization...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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 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.