code portability and function call serialisation.

L

Lefevre

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.
 
V

Victor Bazarov

Lefevre said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top