Simple question about nested execution of constructors



 DEVELOP > c-Plus-Plus > Simple question about nested execution of constructors

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Maciej Kwapulinski"
Date: 12 Jul 2003 06:55:32 AM
Object: Simple question about nested execution of constructors
Hallo,
the following program:
#include <stdio.h>
struct Base {
int a;
Base() {
a=0;
}
Base (int a): a(a) {};
Base (const Base *ob) {
Base(ob->a); // it creates new temporary object Base.
// this is not what I want :((
// I want Base(int) constructor be executed as a
// normal member function an thus initialise a
// variable for me
// in this simple example I could just omit the
// invocation of Base(int), and put assignment
// a=ob->a;
// but of cource it is just a simple program
}
};
main() {
Base a(1);
Base c(&a);
printf("%d\n", c.a); // it does not print '1' value :(((((
}
Can You help me and tell how to properly invoke this nested invocation
Thanks
Maciej
.

User: "Chris \ Val "

Title: Re: Simple question about nested execution of constructors 12 Jul 2003 11:53:34 AM
"Maciej Kwapulinski" <pikpus@wp.pl> wrote in message news:3F0FF734.5000706@wp.pl...
| Hallo,
| the following program:
| #include <stdio.h>
|
| struct Base {
| int a;
| Base() {
| a=0;
| }
| Base (int a): a(a) {};
| Base (const Base *ob) {
Base( const Base *ob ) : a( ob -> a ) {}
If that is not what you're talking about, then please be more specific.
| Can You help me and tell how to properly invoke this nested invocation
I don't see any nesting in your sample ?
Cheers.
Chris Val
.

User: "Victor Bazarov"

Title: Re: Simple question about nested execution of constructors 12 Jul 2003 11:35:30 AM
"Maciej Kwapulinski" <pikpus@wp.pl> wrote...

Hallo,
[...]
Can You help me and tell how to properly invoke this nested invocation

There is no nested invocation. Read the FAQ, section 10.
Hell, read it all while you're at it. Won't hurt. You can
find FAQ here: http://www.parashift.com/c++-faq-lite/
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER