So let's say I have a class called classname and this class has char*
private data member.
In the class that I am taking, the professor wants us to do it like the one below, essentially creating a completely new array.
classname(const classname & source)
{
c_string = new char[strlen(source.c_string)+1];
strcpy(c_string, source.c_string);
}
But what if the two objects essentially share the same single array(that has already been created), like this one.
classname(const classname & source)
{
c_string = source.c_string;
}
I understand this doesn't necessarily do any 'copying' and having different pointers (that belong to different objects) might be risky. But is it considered a copy constructor? Or is it so that in order for it to be a copy constructor the second array must also be created?
From what I've been reading I feel like the second one is the case, but I need a definite NO THAT'S NOT A COPY CONSTRUCTOR to be completely over this in my mind. Thank you.