code portability and function call serialisation.



 DEVELOP > c-Plus-Plus > code portability and function call serialisation.

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Lefevre"
Date: 12 Nov 2003 10:14:34 AM
Object: 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.
.

User: "Victor Bazarov"

Title: Re: code portability and function call serialisation. 12 Nov 2003 10:28:53 AM
"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
.


  Page 1 of 1

1

 


Related Articles
How do you call a regular member function from a static member function?
compilation error: "error: no matching function for call to 'String::String(String)'
Derive other function name from __FUNCTION__? And call the function.
Tasking C166 C++ compiler & temporary objects in function call parameters
Ambiguous call to overloaded function
How to call a function with variable argument list...
Can I call the function in this way
g++ errors out Pass by Reference function call in C++ --- Please HELP
How can I call class member function by a globle function pointer?
exception handling, function call and memory
g++ 3.2.2 error - "no matching function for call to A::setResponse(std::wstring)"
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter
no matching function for call to explicit copy-constructor
avoiding virtual call with pointer to member function
How to call abstract function
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER