How can compiler resolve the correct constructor with default argument?

N

newbie

If I have the following class

Class Test {
public:
Test(int value) _value(value) { _passed = false; }
Test(int value, bool passed = true) _value(value), _passed(passed)
{}
private:
int _value;
bool _passed;
}

main() {
Test mytest(1); // which constructor will be used? what is the
_passed value in this class?
}
 
V

Victor Bazarov

newbie said:
If I have the following class

Class Test {
public:
Test(int value) _value(value) { _passed = false; }
Test(int value, bool passed = true) _value(value), _passed(passed)

Colons seem to be missing in the previous two lines...
{}
private:
int _value;
bool _passed;
}

A semicolon is missing here.

int main() {
Test mytest(1); // which constructor will be used? what is the
_passed value in this class?

The comment seems to be wrapping to the next line. Try using /**/
instead of //

Why don't you try it with your compiler? Get rid of syntax errors
in your code, then see which constructor is picked...

V
 

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
474,202
Messages
2,571,055
Members
47,659
Latest member
salragu

Latest Threads

Top