When I compile Node.cpp
g++ Node.cpp -std=c++11
It gives the following error
Node.h:13:34: error: ‘Node<someType>::Node(const someType&, Node<someType>*)’ cannot be defaulted
= delete means that that function doesn't exist. = default means to use the compiler provide implementation of that function.
1 2 3 4 5 6
//Node foo(...)
//Node(const Node &) = delete;
Node bar(foo); //error: class `Node' can't be copied
//Node(const Node &) = default
Node bar(foo); //will shallow-copy the members.
1 2 3 4 5 6 7 8 9 10 11 12
class asdf{
public:
asdf(int);
};
asdf qwerty; //error: class `asdf' does not have a constructor that takes no parameters
class asdf{
public:
asdf() = default; //now it does, and it uses the implementation provided by the compiler.
asdf(int);
};
So, let's say I want to make Node(const someType&, Node*) the default constructor. Is this possible?? @jlb thanks for the links. I now understand what exactly delete and default does.
So, let's say I want to make Node(const someType&, Node*) the default constructor. Is this possible??
What do you mean by default constructor?
The "default" constructor is the no argument constructor that is supplied by the compiler when you fail to define any constructors. But once you define any constructor this "default" constructor is no longer supplied by the compiler unless you specifically tell the compiler to generate this no argument constructor using the = default.