Candidate::Candidate ()
{
}
Its not doing any thing. Not writing it as it is can't execute the line:
Candidate *list = new Candidate [10];
Why?
Error: no default constructor exists for the class "Candidate"
To allow your dynamic array allocation, new Candidate[10], a default constructor of Candidate must be available. That is, it must be able to take no arguments. If you provide any of your own constructors for Candidate, regardless of how many arguments they take, the implicit default constructor that is usually defined automatically by the compiler will not be defined. You therefore have to provide it yourself, even if its body is empty. See §12.1/5:
A default constructor for a class
Xis a constructor of classXthat can be called without an argument. If there is no user-declared constructor for classX, a constructor having no parameters is implicitly declared as defaulted (8.4).
Your class would be fine as follows because the compiler will implicitly define a defaulted default constructor:
class Candidate
{ }; // Compiler provides a default constructor
But as soon as you give it any other constructor, the implicit default constructor is not provided any more:
class Candidate
{
public:
Candidate(int x);
// A user-defined constructor is provided so the default constructor
// must be defined explicitly
};
You probably have an additional constructor in your class. If you have any constructor defined, the compiler won't generate a default one.
= default it).
std::vector.