I'm getting:
Error 1 error C2514: 'EmployeeListNode' : class has no constructors
in ListOfEmployee.cpp
But in EmployeeListNode.h I have:
class EmployeeListNode
{
friend class ListOfEmployee;
public:
EmployeeListNode(string name, double salary); //A constructor no?
};
I don't understand why it won't recognise that as a constructor. Sorry if this is a stupid question, but I couldn't find an answer through searching.
Edit: The section of the ListOfEmployee that's giving the errors:
void ListOfEmployee::insert(string nameIn, double salaryIn){
EmployeeListNode *n1 = new EmployeeListNode(nameIn, salaryIn);
EmployeeListNode* tn;
if (head){
head = n1;
}else{
for (tn = head; tn->next; tn = tn->next);
}
} Edit 2: And the ListOfEmployee.h in case it makes a difference:
#pragma once
#include<string>
using namespace std;
class EmployeeListNode;
class ListOfEmployee
{
public:
ListOfEmployee();
void insert(string name, double salary);
void display();
void deleteMostRecent();
double getSalary(string name);
~ListOfEmployee();
private:
EmployeeListNode *head;
};
It can be that you only forward-declared ListOfEmployeeNode
, without including it's header (and therefore definition) where it is used.
In that case, the compiler knows about the class, but cannot access any members, including constructors.
If you did include the header, check your include guards. If they happen to be same in the two header files, the definition can be discarded by the preprocessor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With