This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in use of base class constructor in inherited class ?


On Tue, 13 Apr 2004, Andrew Pinski wrote:

>
> On Apr 13, 2004, at 21:21, Nilmoni Deb wrote:
>
> >
> >
> >> This is not a bug and here is why:
> >>  obj2(int a) { obj(a); } // overloaded constructor
> >>
> >> what this really is obj a; and not calling of the constructor.
> >> try this instead:
> >> obj2(int a): obj (a) {}
>
> Because in one case the parser is parsing it as a function call
> while in the other case it is parsing as variable.

Thats obvious.

> The reason why
> it does it that way is because it is ambiguous otherwise so the C++
> standard decided that it will be used to declare a variable instead
> of a function call to the constructor if the first thing is a type
> also.

Thanks. This ambiguity seems to have brought a lot of murkiness. What if
the user wanted something like this:

	obj2(int a, int b) { obj(a); x=b; }

where x is a member of class obj2. Would the compiler accept:

	obj2(int a): obj(a){} { x=b; }

instead ?

On a totally different matter, since the constructor for obj is invoked
prior to the constructor for obj2 (which inherits obj), should the
constructor for obj2 be allowed to invoke the constructor for obj a 2nd
time ?

> I cannot quote the standard word for word on this matter.
>
> Thanks,
> Andrew Pinski
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]