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


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

How member initialization list works?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Stanley Rice <heconghui@gmail.com>
Newsgroups comp.lang.c++
Subject How member initialization list works?
Date Sun, 5 Feb 2012 19:12:28 -0800 (PST)
Organization http://groups.google.com
Lines 39
Message-ID <445005.2165.1328497948225.JavaMail.geo-discussion-forums@prie27> (permalink)
Reply-To comp.lang.c++@googlegroups.com
NNTP-Posting-Host 2001:250:3002:4302:225:b3ff:fe18:96b2
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1328498042 15684 127.0.0.1 (6 Feb 2012 03:14:02 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Mon, 6 Feb 2012 03:14:02 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=2001:250:3002:4302:225:b3ff:fe18:96b2; posting-account=0dCDLwoAAACkPuRK-D_B80d-mGCtIPMz
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:13798

Show key headers only | View raw


Hello all

In the following class definition:

class iStack {
    public:
        iStack( int capacity )
            : _stack( capacity ), _top( 0 ) {}
        // ...
    private:
        vector< int > _stack;
        int _top;
};

The date member _stack is initialized in the form _stack(capacity) in the 
member initialized list. My question, how it could be? the type of _stact 
is vector<int>, but the type of capacity is int.

I wander if the conversion function is called? Then I wrote the following 
code:
    vector<int> va = 2;
but the compiler complains.

However, If the define another class, say, 

class A 
{
public:
    A(int a) : ia(a) {}

private:
    int ia;
};

Then the code 
    A ca = 2;
pass. 

What's the difference ?

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


Thread

How member initialization list works? Stanley Rice <heconghui@gmail.com> - 2012-02-05 19:12 -0800
  Re: How member initialization list works? Goran <goran.pusic@gmail.com> - 2012-02-06 04:12 -0800
  Re: How member initialization list works? Juha Nieminen <nospam@thanks.invalid> - 2012-02-07 06:25 +0000

csiph-web