|
-
January 2nd, 2004, 01:38 PM
#1
could you translate this code in english
Hi,
I was reading Thinking in C++ by Bruce Eckel and I got stuck with this example:
Code:
class X {
int i;
public:
X(int ii = 0);
void modify();
};
X::X(int ii) { i = ii; }
void X::modify() { i++; }
X f5() {
return X();
}
const X f6() {
return X();
}
void f7(X& x) { // Pass by non-const reference
x.modify();
}
int main() {
f5() = X(1); // OK -- non-const return value
f5().modify(); // OK
//! f7(f5()); // Causes warning or error
// Causes compile-time errors:
//! f7(f5());
//! f6() = X(1);
//! f6().modify();
//! f7(f6());
} ///:~
Ok, the line: f5() = X(1), does it say that assign X(1) to the return value of function f5() which is of a type X?
And the: X(1), shouldn`t one need to say: X myXclass(1)??
Why is f7(f5()) illegal? They are both non-const.
-Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|