code portability and function call serialisation.

Discussion in 'C++' started by Lefevre, Nov 12, 2003.

  1. Lefevre

    Lefevre Guest

    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.
    Lefevre, Nov 12, 2003
    #1
    1. Advertising

  2. "Lefevre" <> 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
    Victor Bazarov, Nov 12, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick Gilbert
    Replies:
    4
    Views:
    1,499
  2. Roedy Green

    Serialisation inefficiency

    Roedy Green, Sep 16, 2003, in forum: Java
    Replies:
    8
    Views:
    380
    Robert Olofsson
    Sep 18, 2003
  3. Michael Binz
    Replies:
    0
    Views:
    308
    Michael Binz
    Oct 29, 2003
  4. Pierre Couderc
    Replies:
    1
    Views:
    349
    Victor Bazarov
    Jul 29, 2005
  5. Replies:
    0
    Views:
    246
Loading...

Share This Page