Re: c++: Function style initializer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx> 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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux