T.R | Title | User | Personal Name | Date | Lines |
---|
3584.1 | You need to define a copy constructor and assignment operator | DECC::J_WARD | | Wed May 21 1997 15:33 | 9 |
|
One of the fundamental rules of C++ is that if you
have pointer data members, you need to define your
own copy constructor and assignment operator.
See Scott Meyer's book "Effective C++" rule 11,
"Define a copy constructor and an assignment operator
for classes with dynamically allocated memory.",
for further info.
|
3584.2 | Scott Meyer caused confusion. | CADSYS::BOGDANOV | | Wed May 21 1997 16:53 | 16 |
| .1
>you need to define your
>own copy constructor and assignment operator.
Copy constructor to what? There are no copy constructors or assignments of
classes in the example.
>See Scott Meyer's book "Effective C++" rule 11,
>"Define a copy constructor and an assignment operator
>for classes with dynamically allocated memory.",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>for further info.
There is no dynamic memory allocation. Why do I need them?
>> Serge
|
3584.3 | returning reference to local temporary might be the problem? | DECC::J_WARD | | Wed May 21 1997 17:54 | 19 |
|
you're right.
I can't get it to crash with V5.5 on my machine,
but the problem might be:
operator const SConstChar_p &()
{
return name.str();
}
You're returning a reference to a local temporary.
Does it run ok if you change the above to...
operator SConstChar_p()
{
return name.str();
}
|
3584.4 | | SPECXN::DERAMO | Dan D'Eramo | Wed May 21 1997 20:47 | 13 |
| > You're returning a reference to a local temporary.
Shouldn't the add(b) in main() be equivalent to
add(b.name.x) without any temporaries?
Dan
>void main()
>{
> A b("just a test");
> add(b);
>}
|
3584.5 | Looks like I was tired | CADSYS::BOGDANOV | | Thu May 22 1997 11:07 | 11 |
| Looks like I was confused over the issue of casting to a reference. You a right,
changes in .3 fixed the problem. Another fix is also awailable:
const char *&str() {return x;}
...^
Looks like life-time for temps or something else changed between 5.1 and 5.5.
Thank you for the help.
>> Serge
|