对象创建错误的C++矢量

C++ vector of object creation error

本文关键字:C++ 矢量 错误 创建 对象      更新时间:2023-10-16

我试图给程序中的每个"Person"对象一个"Record"对象的向量。然而,对于我的向量创建,我得到了一个错误:"记录没有在这个范围内声明"。我的Record.cpp和.h文件位于同一src文件夹中。不确定出了什么问题。我必须在Person.h文件中包含Record.h吗?以下代码:

#ifndef PERSON_H
#define PERSON_H
#include <string>
#include <vector>
#include <ctime>

class Person
{
private:
//id, age, name, and date of Person object creation shall be assigned in constructor. The vector 'log' shall be empty at start. 
int id; 
int age; 
std::string name; 
std::vector<Record> log;
time_t t;
struct tm * timeStruct;
public:
Person();
~Person();
};
#endif // PERSON_H
#ifndef PERSON_H
#define PERSON_H
#include <string>
#include <vector>
#include <ctime>
#include "record.h"

class Person
{
private:
//id, age, name, and date of Person object creation shall be assigned in constructor. The vector 'log' shall be empty at start. 
int id; 
int age; 
std::string name; 
std::vector<Record> log;
time_t t;
struct tm * timeStruct;
public:
Person();
~Person();
};
#endif // PERSON_H

这应该为你做