Bug 40173 - Calling a constructor from another constructor of the same class
Summary: Calling a constructor from another constructor of the same class
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-16 17:30 UTC by Tomasz Kurcz
Modified: 2009-05-16 18:38 UTC (History)
2 users (show)

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomasz Kurcz 2009-05-16 17:30:22 UTC
Command line: g++ -pedantic -Wall -o test test.cpp
Compiler output: none


Basically, I created a class with two constructors. One of those is
trying to call the other one. The call doesn't seem to have any effect
at all.

The problem is: g++ allows such a thing with no warnings at all.

Apart from that, I believe such functionality might be useful. For
example, if we've got a constructor with one parameter and quite a
heavy block of code, along with another constructor that takes no
arguments - which we'd like to be a wrapper for the first one, passing
some kind of default value to it.

Thanks for your time ;)
Comment 1 Andrew Pinski 2009-05-16 17:33:37 UTC
>The call doesn't seem to have any effect at all.

Yes it does, it creates another object and calls that constructor.
Comment 2 Paolo Carlini 2009-05-16 18:38:06 UTC
Note, in the next C++ Standard, what the user wants will be possible, see, e.g.:

  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf