Thanks.
But what about my reference from the book
C++ Primer third edition(1998) from Stanley B. Lippman & Jos?e Lajoie
At page 645 of this book, the author says with an example :
A nonstatic data member is restricted to being declared as a pointer or a
reference to an object of its class.
For example :
class Bar {
public:
// ...
private:
static Bar mem1; // ok
Bar *mem2; // ok
Bar mem3; // error
};
Where is the truth ?
jean-marie.
> >hello.
> >i am trying VC++ 7.1 (with vsnet 2003).
[quoted text clipped - 41 lines]
> an object of its class is basic_string::substr, which returns a new string
> that contains the substring.
You aren't trying to define a data member of the class type you are defining
in your example.
Ronald Laeremans
Visual C++
> Thanks.
> But what about my reference from the book
[quoted text clipped - 69 lines]
>> string
>> that contains the substring.
>> All that's required to return an object by value is a copy ctor, and your
>> class Complex has an implicit one.
>>
>> It's conventional for assignment operators, including compound assignment
>> operators like operator+=, to return *this by reference, but it isn't
>> required. Certainly, they can return the object by value
<snip>
Just in case it isn't clear, "returning an object by value" implies
returning a copy of the object.
>Thanks.
>But what about my reference from the book
[quoted text clipped - 14 lines]
>
>Where is the truth ?
As Ronald said, your example didn't do that. A class can't have a non-static
member variable of its own type, because that creates an infinite recursion
scenario. Above, mem3 would contain a Bar* (mem3.mem2) then another Bar
(mem3.mem3), and so on, forever and ever. On the other hand, it's no problem
for non-static member functions of a class X to return X objects or define X
parameters and local variables. You can think of the definitions of all the
member functions defined inside the class body being transported outside the
class to follow the class's definition, at which point the type is complete,
and everything about its object layout is known.

Signature
Doug Harrison
Microsoft MVP - Visual C++
jmd - 14 Dec 2004 22:24 GMT
Ok.
Thank you very much, Doug and Ronald, for your explanations.
Now I "re-understand" these points.
jean-marie.
>>> All that's required to return an object by value is a copy ctor, and
>>> your
[quoted text clipped - 45 lines]
> complete,
> and everything about its object layout is known.