I have created a class, which has a constructor that takes a parameter. Am I right in thinking that I need a copy constructor here?
I have a class, which does not take pointers:
class xyz : public Node
{
public:
xyz( uint8_t node);
xyz(const xyz& cxyz);
~xyz();
private:
uint8_t m_node;
uint16_t m_gainxyz;
And the base:
class Node
{
public:
Node();
virtual ~Node();
protected:
std::string m_name;
And when I do this:
xyz xyz = Initxyz(node);
The compiler tells me to make a copy constructor.
where:
xyz PD::Initxyz(Source& inputNode)
{
if (inputNode.getNodeNumber() > 10 )
{
xyz element(inputNode.getNodeNumber());
element.setInputNode(inputNode);
return element;
}
else
{
std::cout << "ERROR IN XYZ CONFIGURATION" << std::endl;
//Throw Exception;
}
}
But according to what I have read on the web:
If the object has no pointers to dynamically allocated memory, a shallow copy is probably sufficient. Therefore the default copy constructor, default assignment operator, and default destructor are ok and you don't need to write your own.
http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html
Is it also true that I must have one if I use a constructor with parameters?