| View previous topic :: View next topic |
| Author |
Message |
Moritz Beller Guest
|
Posted: Mon Aug 30, 2004 12:17 pm Post subject: (default) constructor/object initializing problem |
|
|
Hi!
Why does Object anObject; call the default constructor Object::Object(),
but Object anObject(); doesn't? Instead, there really seems to be no
call at all.
best regards / Gruß
Moritz Beller
--
web http://www.4momo.de
mail momo dot beller at t-online dot de
gpgkey http://gpg.notlong.com
|
|
| Back to top |
|
 |
Risto Lankinen Guest
|
Posted: Mon Aug 30, 2004 12:23 pm Post subject: Re: (default) constructor/object initializing problem |
|
|
Hi!
"Moritz Beller" <momo.beller.No-Spam (AT) t-online (DOT) de> wrote
Hi!
Why does Object anObject; call the default constructor Object::Object(),
but Object anObject(); doesn't? Instead, there really seems to be no
call at all.
Because "Object anObject();" looks like a function
declaration to the compiler. Nothing is constructed
really; instead the compiler will think that "anObject"
is a function taking no arguments and returning an
instance of "Object".
- Risto -
|
|
| Back to top |
|
 |
Moritz Beller Guest
|
Posted: Mon Aug 30, 2004 1:25 pm Post subject: Re: (default) constructor/object initializing problem |
|
|
On Mon, 30 Aug 2004 12:23:18 GMT
"Risto Lankinen" <rlankine (AT) hotmail (DOT) com> wrote:
| Quote: | Because "Object anObject();" looks like a function
declaration to the compiler. Nothing is constructed
really; instead the compiler will think that "anObject"
is a function taking no arguments and returning an
instance of "Object".
- Risto -
|
Thanks!
best regards
Moritz Beller
--
web http://www.4momo.de
mail momo dot beller at t-online dot de
gpgkey http://gpg.notlong.com
|
|
| Back to top |
|
 |
JKop Guest
|
Posted: Sat Sep 04, 2004 4:18 pm Post subject: Re: (default) constructor/object initializing problem |
|
|
Moritz Beller posted:
| Quote: | On Mon, 30 Aug 2004 12:23:18 GMT
"Risto Lankinen" <rlankine (AT) hotmail (DOT) com> wrote:
Because "Object anObject();" looks like a function
declaration to the compiler. Nothing is constructed
really; instead the compiler will think that "anObject"
is a function taking no arguments and returning an
instance of "Object".
- Risto -
|
Try compile the following:
int main()
{
Object anObject1;
anObject1.MemberFunc();
Object anObject2();
anObject2.MemberFunc();
//Compile error, you can't have a fullstop
//after a pointer. "anObject2" refers to a pointer
//to the function. If you stick in brackets, as in:
anObject().MemberFunc();
//then the function will actually be called
//and the fullstop will access members of the
//object returned from the function
}
-JKop
|
|
| Back to top |
|
 |
|