This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: c++: Function style initializer
- From: "Lokesh Kumar" <lokeshk at gmail dot com>
- To: jorgesmbox-ml at yahoo dot es
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 12 May 2008 21:09:29 -0700
- Subject: Re: c++: Function style initializer
- References: <505424.3210.qm@web27908.mail.ukl.yahoo.com>
Hi Jorges,
I think the default constructor is causing you trouble. Your class A
always has a default constructor that you have over-ridden with your
own defined constructor. To avoid ambiguities, I would also define the
default constructor and use it to do the stuff that I want to do with
null value of par.
HTH,
-Lokesh
On Mon, May 12, 2008 at 6:10 PM, <jorgesmbox-ml@yahoo.es> wrote:
> Hi,
> I experienced something I consider strange: Let me try to explain by a simpe example:
>
> Definitions:
>
> class B;
>
> class A {
> A(B par=0);
> }
>
> Now, if I use:
>
> A myA(myB); // assume myB is of type B
>
> then I have an object of type A created, but if I do:
>
> A myA();
>
> Then no object of type A is created. I thought that because of the default value in the constructor, I could create myA
> this way, but I get no error nor object. I was beaten by this last week, and it cost me many hours to debug. Am I missing something? Forgive me if the answer is trivial, I am not an expert in c++ and besides I started coding again after more than a year. Pointers are also appreciated, I have the latest Stroustrup's but I just started it and a search didn't answer this question.
>
> jorges
>
>
>
>
> ______________________________________________
> Enviado desde Correo Yahoo! La bandeja de entrada más inteligente.
>
--
"It is not God that is worshipped but the group or authority that
claims to speak in His name. Sin becomes disobedience to authority not
violation of integrity."
Lokesh Kumar
Mobile: +1 917 319 0360