我正在为一个学校项目编写一个模拟共享编辑器(如 Google Docs)的小程序
我已经编写了我需要的所有类,但是当我尝试构建程序时,我得到了这个错误:
error: unknown type name 'NetworkServer'
NetworkServer &_server;
error: use of undeclared identifier 'SharedEditor' std::vector<SharedEditor*> SEditors;
error: expected expression std::vector<SharedEditor*> SEditors;
error: unknown type name 'SharedEditor' int connect(SharedEditor* sharedEditor);
这是我的 .h 文件
网络服务器.h
#include <vector>
#include <queue>
#include "SharedEditor.h"
#include "Message.h"
class NetworkServer {
private:
std::vector<SharedEditor*> SEditors;
std::vector<int> idEditors;
std::queue<Message> messages;
public:
int connect(SharedEditor* sharedEditor);
int disconnect(SharedEditor* sharedEditor);
void send(const Message& m);
void dispatchMessages();
};
共享编辑器.h
#include "NetworkServer.h"
#include "Message.h"
#include "Symbol.h"
class SharedEditor {
private:
NetworkServer& _server;
int _siteId{};
std::vector<Symbol> _symbols;
int _counter;
public:
SharedEditor() = delete;
SharedEditor(NetworkServer& server);
void localInsert(int index, char value);
void localErase(int index);
void process(const Message& m);
std::string to_string();
int getSiteId() const;
};
符号.h
#include <vector>
class Symbol {
private:
char value;
int idClient;
int num;
std::vector<int> pos;
public:
Symbol(char value, int client, int num, std::vector<int> pos);
char getValue() const;
int getIdClient() const;
int getNum() const;
const std::vector<int> &getPos() const;
};
消息.h
#include <vector>
class Message {
bool insert; // true --> insert || false --> delete
int _siteId;
int num;
char value{};
std::vector<int> pos;
public:
Message(bool insert, int siteId, int num, char value, std::vector<int> pos);
Message(bool insert, int siteId, int num);
bool isInsert() const;
int getSiteId() const;
int getNum() const;
char getValue() const;
const std::vector<int> &getPos() const;
};
我不明白我在哪里做错了。顺便说一句,我正在使用 CLion