| 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/
.
|
|
|
|

|
Related Articles |
|
|