By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

code portability and function call serialisation.

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Lefevre" <be************@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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.