constructor call

Pages: 12
You can buy the standard here: http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=50372

Most of us just use the latest free draft that is almost the same as the real standard http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
There was a free draft that was identical to the real standard but they removed it. You can probably find that draft or the real standard if you search for it.
closed account (zb0S216C)
hooshdar3 wrote:
"+I got the idea from reading Herbet Shieldt's text that copy constructor is optional.true?"

His books normally contain bad practices; be wary. As for the copy-constructor begin optional, the compiler has the last say, because the compiler will implicitly create its own copy-constructor only if its use is required. For instance:

This code will generate a copy-constructor:

1
2
3
4
5
6
7
8
9
struct Object
{
    int a_;
};

int main()
{
    Object a_, b_(a_); 
}

Since b_ depends on the state of a_, the compiler will generate a copy-constructor for b_ but not a_, because a_ didn't require the use of the copy-constructor.

Scott Meyers wrote:
"NamedObject declares neither copy constructor nor copy assignment operator, so compilers will generate those functions (if they are needed). "


Wazzak
Last edited on
Framework (2534) Jun 27, 2012 at 3:29pm
hooshdar3 wrote:
"+I got the idea from reading Herbet Shieldt's text that copy constructor is optional.true?"

His books normally contain bad practices; be wary. As for the copy-constructor begin optional, the compiler has the last say, because the compiler will implicitly create its own copy-constructor only if its use is required. For instance:

This code will generate a copy-constructor:

1
2
3
4
5
6
7
8
9



struct Object
{
int a_;
};

int main()
{
Object a_, b_(a_);
}


Since b_ depends on the state of a_, the compiler will generate a copy-constructor for b_ but not a_, because a_ didn't require the use of the copy-constructor.

Scott Meyers wrote:
"NamedObject declares neither copy constructor nor copy assignment operator, so compilers will generate those functions (if they are needed). "


Wazzak


What about my example code?the constructors are called 6 times?What about copy- or defaault-ctor each?
Topic archived. No new replies allowed.
Pages: 12