Re: copy conctructor?
asifalli.khan@gmail.com wrote:
Hi,
Please learn to quote correctly
(http://en.wikipedia.org/wiki/Top-posting and
http://cfaj.freeshell.org/google/ if you use Google Groups).
is there any name to those 4 type of copy conctructor.
No, they are all copy constructors.
1)Is there any conctructor exits named syclo or clone conctructor.
Cloning an object is more an idiom than a language feature. Cloning (as
opposed to copy-constructing) is important when all you have is a
pointer to a base class and you must copy the object. Since you have no
way of knowing the object's original type, the easiest way would be to
add a virtual function clone() that would return a new object on the
heap.
# include <memory>
class base
{
public:
virtual base* clone() = 0;
};
class derived_1 : public base
{
public:
virtual derived_1* clone()
{
return new derived_1(*this);
}
};
class derived_2 : public base
{
public:
virtual derived_2* clone()
{
return new derived_2(*this);
}
};
void f(base& b)
{
// I want to copy 'b', but what is it?
// ah!
std::auto_ptr<base> bb(b.clone());
}
I never heard of a "syclo" constructor.
Jonathan