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

Mixing default and non-default parameters in Constructor?

Are there some way to mix default and non-default parameters in a
constructor:

class test {

public:
test(int i = 45, int j) : pp(j){}
private:
int pp;
int i;
};

The above does not work and gives the error:

main.cpp:144: error: default argument missing for parameter 2 of
‘test::test(int, int)’
make: *** [main.o] Error 1
Jun 6 '07 #1
2 4415
desktop wrote:
Are there some way to mix default and non-default parameters in a
constructor:

class test {

public:
test(int i = 45, int j) : pp(j){}
private:
int pp;
int i;
};

The above does not work and gives the error:

main.cpp:144: error: default argument missing for parameter 2 of
‘test::test(int, int)’
make: *** [main.o] Error 1
Yes, but default arguments have to be the last one[s].

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 6 '07 #2
desktop wrote:
Are there some way to mix default and non-default parameters in a
constructor:

class test {

public:
test(int i = 45, int j) : pp(j){}
test(int j, int i_ = 45) : pp(j), i(i_) { }
private:
int pp;
int i;
};

The above does not work and gives the error:

main.cpp:144: error: default argument missing for parameter 2 of
‘test::test(int, int)’
make: *** [main.o] Error 1

Default parameters must be at the *end* of the parameter list.
Note also, that you did not initialize your member variable "i".
Jun 6 '07 #3

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

Similar topics

3
by: bergel | last post by:
Hello, Does anyone already have some experience in mixing AWT and Swing? Is it conceptually doable? Does the design of Swing prevent interaction between an AWT and a Swing widget? Regards,...
6
by: Russell E. Owen | last post by:
At one time, mixing for x in file and readline was dangerous. For example: for line in file: # read some lines from a file, then break nextline = readline() # bad would not do what a naive...
4
by: Rudolf | last post by:
Is it possible to add a vb.net source code module to a c# project and if so how? Thanks Rudolf
2
by: puzzlecracker | last post by:
I am writing a C++ program under linux and one of the modules uses c for file system calls to traverse and retrieve files, etc. I am thinking of writing that module purely in C and linking into my...
9
by: Pascal Cloup | last post by:
Hello, I write a Dll of managed C++ class that contains a piece of code like the following liines. This code always fails when attempting to create a new not managed class. Someone has an...
2
by: Daniel Frechette | last post by:
Hi, Is it possible to have secured (SSL/HTTPS) and non-secured (HTTP) content in the same page without breaking the security? I am developing a secured reservation system in which the user can...
28
by: ziman137 | last post by:
Hello all, I have a question and am seeking for some advice. I am currently working to implement an algorithmic library. Because the performance is the most important factor in later...
2
by: Ralf Goertz | last post by:
Hi, can I mix output to cout and wcout? It seems that if I write to cout first it works fine but if I start with wcout the output to cout vanishes. I assume that is has to do with the...
13
by: tesis | last post by:
Hi all gurus; forgive me if I'm writing about a basic question. I need to call a secured (SSL) page from a .aspx page. Calling an absolute URL rises an error (invalid path... Virtual path...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. I have a website written entirely in classic ASP. My customer has asked if I can place one (1) aspx page into the website. They don't want the domain name to change between the aspx &...
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...
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?
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,...

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.