【发布时间】:2014-05-10 02:02:14
【问题描述】:
我无法摆脱代码中的几个编译错误。我在程序的其他地方使用过类似的语法没有问题,所以我不确定是什么问题。
在 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
在 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
编译器错误读取
PersonalRec.h:错误:在 'fName' 之前需要 ')'
和
PersonalRec.cpp: error: '(' token 之前的预期构造函数、析构函数或类型转换
我觉得他们是相关的。
编辑 - 第一个错误可以通过在 std::string fName 中添加字符串 fName 来修复,对于 lName 也是如此。该行的修改代码是
PersonalRec (std::string fName, std::string lName, Date bDate);
编辑 2 - 我对第二个错误做了同样的事情并且代码编译。
【问题讨论】:
标签: c++