![]() |
code portability and function call serialisation.
Hello.
I recently discovered that this kind of code : | struct Object | { | string f() { return string("Toto"); } | } | | int main( ... ) | { | Object o; | | cout << o.f().c_str() << endl; | | return 0; | } Is working fine with SUN's C++ compilers and Visual C++ 6 (compiler) but not fine at all with AIX ones. What is the status of this kind of code ( o.f().g().h().j() ) a) Is this part of the C++ standard ? b) Is this only a features that is supposed by the standard to be compiler dependent ? c) Is this an AIX compiler bug ? I would say the answer is the b) one, but i'm not sure. What is your point of view about this ? Regards. Benoit Lefevre. |
Re: code portability and function call serialisation.
"Lefevre" <benoit.lefevre@reuters.com> wrote...
> Hello. > > I recently discovered that this kind of code : > > | struct Object > | { > | string f() { return string("Toto"); } 'string' is undefined. Did you forget to include a header, maybe? > | } Missing ; here. > | > | int main( ... ) There is no allowed declaration of 'main' that would accept any number and types of arguments. It's either (void) or (int, char*[]). > | { > | Object o; > | > | cout << o.f().c_str() << endl; > | > | return 0; > | } > > Is working fine with SUN's C++ compilers and Visual C++ 6 (compiler) > but not fine at all with AIX ones. > > What is the status of this kind of code ( o.f().g().h().j() ) > > a) Is this part of the C++ standard ? Pretty much. If a member function returns an object (or a reference to an object), another member function can be called using operator. (operator "dot"). > > b) Is this only a features that is supposed by the standard to be > compiler dependent ? Nope. BTW, they have been in the language since the beginning, I believe. > > c) Is this an AIX compiler bug ? Your code is not compilable. Post the real code, post the compiler diagnostic messages you're getting, then we could try to determine whether it's a compiler's fault. > > I would say the answer is the b) one, but i'm not sure. I would say you need to study C++ a bit more. > > What is your point of view about this ? My point of view is that you need to post real code, not something you just remembered and typed in with tons of errors into a message. Victor |
| All times are GMT. The time now is 07:49 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.