J
Joost Ronkes Agerbeek
Is it legal to reassign an auto_ptr to another auto_ptr that is a member of
the object the auto_ptr is holding before the reassignment? (Confused yet?
)
#include <memory>
class Node
{
public:
Node() : next(0) {}
Node(Node* node) : next(node) {}
std::auto_ptr<Node> next;
};
void main()
{
Node node(new Node(new Node()));
node.next = (*node.next).next; // <-- is this valid?
}
As I see it, this program could cause problems if the object node.next owns
is deleted before (*node.next).next is evaluated. I even think the auto_ptr
assignment operator needs to make a temporary copy of (*node.next).next.
The above code compiles and runs on my system, but is it legal according to
the C++ Standard?
tia,
Joost
the object the auto_ptr is holding before the reassignment? (Confused yet?
)
#include <memory>
class Node
{
public:
Node() : next(0) {}
Node(Node* node) : next(node) {}
std::auto_ptr<Node> next;
};
void main()
{
Node node(new Node(new Node()));
node.next = (*node.next).next; // <-- is this valid?
}
As I see it, this program could cause problems if the object node.next owns
is deleted before (*node.next).next is evaluated. I even think the auto_ptr
assignment operator needs to make a temporary copy of (*node.next).next.
The above code compiles and runs on my system, but is it legal according to
the C++ Standard?
tia,
Joost