Reputation: 11
I'm having trouble getting rid of a couple of compile errors in my code. I've used similar syntax elsewhere in the program without a problem, so I'm not sure what's wrong.
In PersonalRec.h:
#ifndef PersonalRec_H
#define PersonalRec_H
class PersonalRec
{
public:
PersonalRec ();
PersonalRec (string fName, string lName, Date bDate); //This line shows the first error
protected:
void displayPersonalRec() const;
int getAgeInYears() const;
private:
std::string FirstName;
std::string LastName;
Date DoB;
};
#endif
In PersonalRec.cpp:
#include<iostream>
#include<string>
#include<math.h>
#include "Date.h" //contains prototypes for Date class
#include "PersonalRec.h"
extern Date currentDate;
PersonalRec::PersonalRec()
{
}
PersonalRec::PersonalRec(string fName, string lName, Date bDate) //This line shows the second error
{
FirstName = fName;
LastName = lName;
DoB = bDate;
displayPersonalRec();
}
//Implementations of protected methods follow
The compiler errors read
PersonalRec.h: error: expected ')' before 'fName'
and
PersonalRec.cpp: error: expected constructor, destructor, or type conversion before '(' token
I have a feeling they are related.
EDIT - The first error can be fixed by prefacing string fName into std::string fName and the same for lName. The modified code for that line is
PersonalRec (std::string fName, std::string lName, Date bDate);
EDIT 2 - I did the same thing for the second error and the code compiles.
Upvotes: 1
Views: 1995
Reputation: 21627
My guess is that you need
#include <string>
in your .h file and that you need to prefix string with std::string there.
Upvotes: 1