Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

parameterized constructor with missing fields?

16 views
Skip to first unread message

pedr...@lycos.com

unread,
Apr 18, 2018, 7:35:28 AM4/18/18
to
I have some code of the form:

C::C( int a, int b, int c): X(a), Y(b), Z(c) {
....
}

Sometimes it is invoked
new C(i,j,1)
but others
new C(m,n)

So what happens with the latter?
final element Z(c) is undefined?

James R. Kuyper

unread,
Apr 18, 2018, 9:04:54 AM4/18/18
to
In order for the second constructor call to be compilable, either
there's a declaration for the constructor that is in scope which
provides a default value for the third parameter, or there's a
declaration in scope for a different constructor that takes only two
arguments.

Bo Persson

unread,
Apr 18, 2018, 9:05:20 AM4/18/18
to
That just doesn't compile.

Either there must be a different constructor with fewer parameters, or c
must have a default value.


Bo Persson

0 new messages