Silver bullet for C++ memory management ?
Hi there,
I've been using smart pointer to save my efforts on dealing with
memory management in C++. A sample of code is as below.
//////// begin of code /////////
#define PtrOf(X) boost::shared_ptr < X >
....
class Animal {
public:
Animal(const std::string& name) { _name = name; }
private:
std::string _name;
};
....
PtrOf(Animal) animal(new Cow());
....
//////// end of code /////////
It has been worked well, however there are two ugly problems:
1) If we put the macro in a class interface, it's really ugly and
obstruct the clarity of the interface.
class Farm {
public:
Farm(PtrOf(Animal) a);
};
2. More seriously, if we have to use some 3rd party libraries which do
not use the same convention, instead using bare pointer, we have a
bigger problem to deal with.
My question is whether there is a way to address C++ memory management
to reduce it to a painless task ( as Java and C# ) without using 3rd
party garbage collector ?
Thanks,
Ken
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]