T
Tony Johansson
Hello Experts!
I have the definition of class Integer below and a main.
Now to my question in main below I have statement (1) which is Integer m =
k.clone(); but actually as I think
statement(1) and statement(2) and statement(3) does mean exactly the same
thing. I'm I right?
(1)Integer m = k.clone();
(2)Integer m(k); //copy constructor
(3)Integer m = k; //another way of writing a copy constructor
main()
{
Integer k(5);
Integer m = k.clone();
}
class Integer
{
public:
Integer(int n= 0)
{
value = n;
}
Integer clone() const
{
Integer res(value);
return res;
}
private:
int value;
};
Many thanks!
//Tony
I have the definition of class Integer below and a main.
Now to my question in main below I have statement (1) which is Integer m =
k.clone(); but actually as I think
statement(1) and statement(2) and statement(3) does mean exactly the same
thing. I'm I right?
(1)Integer m = k.clone();
(2)Integer m(k); //copy constructor
(3)Integer m = k; //another way of writing a copy constructor
main()
{
Integer k(5);
Integer m = k.clone();
}
class Integer
{
public:
Integer(int n= 0)
{
value = n;
}
Integer clone() const
{
Integer res(value);
return res;
}
private:
int value;
};
Many thanks!
//Tony