P
puzzlecracker
I am using pointers in my program and they obviously make me a bit
nervious about possible program states. I am giving serious thoughs
about using auto_ptr but unsure whether they can be placed in vectors.
This is approximaton of where I need to use them
/currently
class A {
//some members
virtual ~A();
};
class B
ublic A {
//some members
};
class C {
public:
std::vector<A*> vec;
~c(){// I do the clean up here}
};
....
I am considering the revision to
include<memory>
class C {
public:
std::vector<auto_ptr<A*> > vec;
};
During the execution I remove as well as add as well as modify the
content of the vector. Does anyone think whether it might conflict with
ownership issues in the auto_ptr<A*>;
----
another problem, this time unrelated to auto_ptr. I maintain a vecotr
of pointers where copies of some of this pointers are being kept
outside. Ex.
class A {
};
class B{
A * const a; // pay attention: I cannot modify the content of a
// B has a copy of *a which is stored in the vector C
};
class C {
vector<A *> vec;
};
Only issues I currenly forsee is that copy of a pointer in B can be
invalidated if destroyed in vec, but can it become invalidate by some
other vector operations?
would this scheme work if I were to use auto_ptr instead?
unfortunately, I cannot use boost lib for my production code (so, there
is not shared_ptr or valjue_ptr available to me).
Thank
nervious about possible program states. I am giving serious thoughs
about using auto_ptr but unsure whether they can be placed in vectors.
This is approximaton of where I need to use them
/currently
class A {
//some members
virtual ~A();
};
class B
//some members
};
class C {
public:
std::vector<A*> vec;
~c(){// I do the clean up here}
};
....
I am considering the revision to
include<memory>
class C {
public:
std::vector<auto_ptr<A*> > vec;
};
During the execution I remove as well as add as well as modify the
content of the vector. Does anyone think whether it might conflict with
ownership issues in the auto_ptr<A*>;
----
another problem, this time unrelated to auto_ptr. I maintain a vecotr
of pointers where copies of some of this pointers are being kept
outside. Ex.
class A {
};
class B{
A * const a; // pay attention: I cannot modify the content of a
// B has a copy of *a which is stored in the vector C
};
class C {
vector<A *> vec;
};
Only issues I currenly forsee is that copy of a pointer in B can be
invalidated if destroyed in vec, but can it become invalidate by some
other vector operations?
would this scheme work if I were to use auto_ptr instead?
unfortunately, I cannot use boost lib for my production code (so, there
is not shared_ptr or valjue_ptr available to me).
Thank