Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #14371

Re: question on no-argument constructor

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: question on no-argument constructor
Date 2012-02-21 14:32 +0100
Organization A noiseless patient Spider
Message-ID <ji06e9$tjp$1@dont-email.me> (permalink)
References <18415058.42.1329830819543.JavaMail.geo-discussion-forums@vbne13>

Show all headers | View raw


On 21.02.2012 14:26, Oliver wrote:
> hi, all -
>
> I have a newbie question: suppose I have a user-defined class that
> must take a argument to properly initialize. so I have something like:
>
> class Foo {
>     explicit Foo(const string&str);
> ...
> }
>
> Another class define Foo as its member:
>
> class Bar {
>
> private:
>     Foo foo;
> }
>
> Now the compiler complains that it can find the candidate constructor.
> So it seems I must define a no-argument constructor for Foo ...

Yes.


> at the  risk of the object can exist without being properly initialized?

No.


> I must  have missed something ...

Yes, but it's difficult to say what.


Cheers & hth.,

- Alf

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

question on no-argument constructor Oliver <fwang2@gmail.com> - 2012-02-21 05:26 -0800
  Re: question on no-argument constructor "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-02-21 14:32 +0100
    Re: question on no-argument constructor Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-21 05:44 -0800
  Re: question on no-argument constructor "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-02-21 14:44 +0100
    Re: question on no-argument constructor Oliver <fwang2@gmail.com> - 2012-02-21 06:41 -0800
      Re: question on no-argument constructor Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-21 08:14 -0800
        Re: question on no-argument constructor Juha Nieminen <nospam@thanks.invalid> - 2012-02-21 17:00 +0000
      Re: question on no-argument constructor Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-21 21:12 +0000
      Re: question on no-argument constructor Goran <goran.pusic@gmail.com> - 2012-02-21 23:44 -0800

csiph-web