C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

(default) constructor/object initializing problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Moritz Beller
Guest





PostPosted: Mon Aug 30, 2004 12:17 pm    Post subject: (default) constructor/object initializing problem Reply with quote



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





PostPosted: Mon Aug 30, 2004 12:23 pm    Post subject: Re: (default) constructor/object initializing problem Reply with quote



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





PostPosted: Mon Aug 30, 2004 1:25 pm    Post subject: Re: (default) constructor/object initializing problem Reply with quote



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





PostPosted: Sat Sep 04, 2004 4:18 pm    Post subject: Re: (default) constructor/object initializing problem Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.