Given the class "A" exists and is correct. What will be some negative results of using the reference to "A" instead of the pointer in the class "B". I.e:
// In Declaration File class A; class B { public: B(); ~B(); private: A& a; }; // In Definition File B::B(): a(* new A()) {} B::~B() { delete &a; }
Missing additional code for further B correctness, such as the copy constructor and assignment operator, simply wanted to demonstrate the concept of the question.
Immediate restrictions are as follows:
A
B
0
:
std::vector<B*>
, .
, a , . . , -POD ( -POD - , ).
, , .
, B, , ; a.
a
, , , delete &a . , new, , , , , B.
delete &a
new
, , , - (std:: unique_ptr, std:: shared_ptr ..). .
; , , , , . , .
, , , , , , , , , , . , ,