Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7019
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Newsgroups | alt.comp.lang.learn.c-c++, comp.lang.c++ |
| Subject | Re: Class declaration: TMember Member(); vs TMember Member; |
| Date | 2011-06-21 10:33 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <itqa3v$vvv$1@dont-email.me> (permalink) |
| References | <d931b$4e00aa4a$5419acc3$24521@cache3.tilbu1.nb.home.nl> |
Cross-posted to 2 groups.
On 6/21/2011 10:27 AM, Skybuck Flying wrote:
> Hello,
>
> I have a question about the parenthesis (see *) and further consequences
> of it in the following example class:
>
> class TSomeClass
> {
> TSomeOtherClass mSomeOtherClass1(); // *
> TSomeOtherClass mSomeOtherClass2;
>
> void SomeRoutine();
Explain to yourself the difference between
sometype blah();
and
someothertype blahblah();
and then explain to yourself the difference between
TSomeOtherClass mBlah();
and
void SomeBlah();
. Perhaps after that you're going to see by yourself what the
difference is between
SomeType someName;
and
SomeType someName();
(i.e. what the importance of the parentheses is).
> };
>
>
> void TSomeClass::SomeRoutine()
> {
> mSomeOtherClass1.SomeRoutine(); // does not compile
> // compiler error message:
> // error: nonstandard form for taking the address of a member function
> // error: expression must have class type
>
> mSomeOtherClass1->SomeRoutine(); // does not compile
> // error: nonstandard form for taking the address of a member function
> // error: expression must have pointer type
>
>
> mSomeOtherClass2.SomeRoutine(); // compiles just fine.
> }
>
> So what is the effect of the parenthesis at // *.
Read the FAQ section 10.
> To me it looked as if the default constructor for mSomeOtherClass1 was
> being called ?
Yes, that's common among beginners, we've pretty much all been there.
> But perhaps something else is happening which causes the
> mSomeOtherClass2.SomeRoutine call to fail to compile ?!
>
> Does mSomeOtherClass2 need to be "constructed" by calling it's
> constructor in the default constructor of TSomeClass or is that
> automatic (so when parenthesis in the member declaration are left out) ?.
>
> Bye,
> Skybuck.
V
--
I do not respond to top-posted replies, please don't ask
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Class declaration: TMember Member(); vs TMember Member; "Skybuck Flying" <Windows7IsOK@DreamPC2006.com> - 2011-06-21 16:27 +0200 Re: Class declaration: TMember Member(); vs TMember Member; "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-21 16:36 +0200 Re: Class declaration: TMember Member(); vs TMember Member; Victor Bazarov <v.bazarov@comcast.invalid> - 2011-06-21 10:33 -0400
csiph-web