C++ 错误:在"("令牌之前进行预期的构造函数、析构函数或类型转换
C++ Error: Expected constructor, destructor, or type conversion before '(' token
我在处理代码中的几个编译错误时遇到了麻烦。我在程序的其他地方使用了类似的语法,没有问题,所以我不确定是哪里出了问题。
在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: error: expected ')' before 'fName'
和
PersonalRec.cpp:错误:在'(' token
之前期望构造函数、析构函数或类型转换
我有一种感觉他们是有关系的。
EDIT -第一个错误可以通过将string fName前缀为std::string fName和lName前缀来修复。该行修改后的代码是
PersonalRec (std::string fName, std::string lName, Date bDate);
编辑2 -我对第二个错误做了同样的事情,代码编译。
我猜你需要
#include <string>
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- new[] / delete[] 并在C++中抛出构造函数/析构函数
- 创建/向容器添加对象时如何使用构造函数/析构函数
- LNK2019构造函数/析构函数使用 C++ Dll
- 有人可以解释一下这里发生了什么(类和构造函数/析构函数)吗?
- 带智能ptr的Pimpl-为什么需要构造函数/析构函数
- 需要构造函数/析构函数/类型转换错误
- Boost共享指针构造函数/析构函数
- 通过值或引用调用时未调用构造函数/析构函数.不管怎样
- C++构造函数析构函数中的奇怪行为
- 构造函数/析构函数链接错误
- 在模板化函数中调用具有特征的显式构造函数/析构函数
- c++构造函数/析构函数
- 为什么赋值的成本不能保证小于构造函数-析构函数对
- 重写默认构造函数/析构函数而不实现它们
- 使用自定义分配器调用对象构造函数/析构函数
- 涉及类和结构的构造函数/析构函数
- 在抽象构造函数/析构函数中调用纯虚拟函数安全吗
- 如果在没有限定的情况下从构造函数/析构函数调用虚拟函数,则是否会发生虚拟调度
- C++基于堆栈的构造函数/析构函数无法按预期工作