By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

How can compiler resolve the correct constructor with default argument?

P: n/a
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?
}

Aug 9 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
newbie wrote:
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.
>
main() {
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 9 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.