Hello,
I am a newbie user of boost.
I have a question about boost::shared_ptr. Suppose you have a
polimorphic list:
class entity{ ...};
class simple_entity : public entity{
public:
uint id;
simple_entity(uint i) : id(i) {}
};
int main(){
list l;
...
I noticed the following code doesn't compile
l.push_back(new simple_entity(1));
too bad, because it was very easy to read, and very similar to the
behavior if standard pointers (not to speak about similarity to Java
and C#). So I am forced to do
l.push_back(shared_ptr<entity> (new simple_entity(1)));
which is less readable and, IMHO, barely tolerable on the long
run: too much typing.
It seems that the reason is the explicit keyword in the
constructor. My question is: why? what was the danger without the
explicit?
Thank you very much for any info,
Maurizio