Initialising a constant object

Discussion in 'C++' started by Fraser Ross, Nov 28, 2008.

  1. Fraser Ross

    Fraser Ross Guest

    Am I right in thinking that a constant object of a class must have an
    accessible user provided constructor if it is not list-initialised?

    Fraser.
     
    Fraser Ross, Nov 28, 2008
    #1
    1. Advertising

  2. On Nov 28, 4:25 pm, "Fraser Ross" <> wrote:
    > Am I right in thinking that a constant object of a class must have an
    > accessible user provided constructor if it is not list-initialised?


    You are quite right.

    --
    Max
     
    Maxim Yegorushkin, Nov 28, 2008
    #2
    1. Advertising

  3. Fraser Ross

    Fraser Ross Guest

    >> Am I right in thinking that a constant object of a class must have an
    >> accessible user provided constructor if it is not list-initialised?


    >You are quite right.


    class B {
    };

    class A {
    B b_;
    public:
    A() {}
    };

    B const b={};
    A const a;

    void func() {
    B const b={};
    A const a;
    }

    Borlands compiler confirms my deductions with the above code.

    Fraser.
     
    Fraser Ross, Nov 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Kohout

    Initialising a constant from a file

    Peter Kohout, Sep 7, 2003, in forum: C++
    Replies:
    4
    Views:
    314
    Thomas Matthews
    Sep 8, 2003
  2. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,094
  3. Martin Magnusson
    Replies:
    2
    Views:
    508
    John Harrison
    Oct 8, 2004
  4. nrhayyal
    Replies:
    8
    Views:
    303
    Bogdan Sintoma
    Sep 22, 2005
  5. Christoph Conrad
    Replies:
    2
    Views:
    319
    Christoph Conrad
    Mar 1, 2007
Loading...

Share This Page