我有两个类:User.h和Room.h,它们都包含一个指向另一个类(用户到房间和空间到用户)的对象。 我想我知道如何包含.h文件,但我仍然在我的.cpp文件(user.cpp)之一中发生错误。两个类包含彼此的成员
user.h
#ifndef USER_H
#define USER_H
class Room;
using namespace std;
class User
{
private:
Room* _currRoom;
public:
//some functions...
};
#endif
room.h
#ifndef ROOM_H
#define ROOM_H
#include "User.h"
class Room
{
private:
vector<User*> _users;
User* _admin;
int _maxUsers;
int _questionTime;
int _questionsNo;
string _name;
int _id;
public:
Room(int id, User* admin, string name, int maxUsers, int questionsNo,int questionTime);
//more functions...
};
#endif
我包含在user.cpp room.cpp和room.h user.h什么问题我做了什么?
你不应该包含'cpp'文件 – Rakete1111
如果你有错误,你应该分享它们。我们喜欢错误文本。 – NathanOliver
错误错误C2514:'Room':class没有构造函数,我在user.cpp中调用构造函数 – abcdef123