Hi everyone!
When i compile my small piece of code it gives me the error C2512 : No appropriate default constructor available
this is my definition of class person:
// Person.h
// A class defining a person
#pragma once
#include <iostream>
#include <string>
#include <functional>
using std::cout;
using std::endl;
using std::string;
class Person
{
public:
Person(string first, string second);
// Less-than operator
bool operator<(const Person& p)const ;
// Get the name
string getName()const;
private:
string firstname;
string secondname;
};
Here is my implementation :
#include "Person.h"
Person::Person(string first = "", string second = "")
{
firstname = first;
secondname = second;
}
string Person::getName()const
{
return firstname + " " + secondname;
}
bool Person::operator<(const Person& p)const
{
if(secondname < p.secondname ||
((secondname == p.secondname) && (firstname < p.firstname)))
return true;
return false;
}
When i combine the definition and implementation into a single file Person.h the error disappears. Im confused. Would some one please help?