循环依赖项 '{'令牌之前的预期类名
Circular dependency expected class-name before '{' token
很抱歉提前启动另一个循环依赖线程,但我几乎尝试了所有方法,也许一双新鲜的眼睛会有所帮助。我如何编译这个 *?
卡。H
#ifndef CARD_H
#define CARD_H
#include <string>
#include <sstream>
#include <irrKlang.h>
#include "Database.h"
using namespace std;
using namespace irrklang;
class Card: public Database{ // problem expected class-name before '{' token
public:
数据库。H
#ifndef __DATABASE_H__
#define __DATABASE_H__
#include <string>
#include <vector>
#include <sqlite3.h>
#include <wx/string.h>
#include <irrKlang.h>
#include <wx/file.h>
#include "Card.h" // even though i include card.h
using namespace std;
using namespace irrklang;
class Card; // if i take this out, I get: 'Card' was not declared in this scope|
class Database
{
public:
vector<Card> queryC(wstring query);
帮助防止循环依赖的两个规则:1.) 如果不需要类的实现,请仅通过前向引用声明它。2.) 如果需要实现,请尽可能晚地包含头文件。
卡.h
#ifndef CARD_H
#define CARD_H
#include "Database.h"
class Card : public Database {
public:
int card;
};
#endif // #ifndef CARD_H
数据库.h
#ifndef DATABASE_H
#define DATABASE_H
#include <vector>
#include <string>
class Card;
class Database {
public:
std::vector<Card> queryC(std::string query);
};
#endif // #ifndef DATABASE_H
卡.cpp
#include "Card.h"
Card card;
数据库.cpp
#include "Database.h"
Database database;
.
$ g++ -c Card.cpp -o Card.o
$ g++ -c Database.cpp -o Database.o
$ ls -l Card.o Database.o
-rw-r--r-- 1 user group 959 19. Sep 09:13 Card.o
-rw-r--r-- 1 user group 967 19. Sep 09:13 Database.o
相关文章:
- 如何在C++中使用X509证书模在令牌中查找私钥
- holeMenuProgram.cpp:38:1 错误:'}'令牌之前的预期主表达式
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- Arduino 用于语句错误。令牌之前的预期')' ';'。如何解决这个问题?
- 错误:令牌 { '{' 之前应存在非限定 ID
- 允许哪些令牌作为 #include 的参数?
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 它在 { 令牌之前给了我预期的标识符
- (错误:令牌之前'<<'预期的主表达式)
- 为什么 ## aka 令牌粘贴运算符不适用于 C 和 C++ 中的注释?
- 错误:"->"令牌之前的预期初始值设定项
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 丢失读入的每一行输入中的最后一个令牌
- 如何使用 libCurl 将访问令牌发送到服务器 API
- C++令牌定义成员
- 宏定义中的预处理器令牌两边有两个双引号
- 错误:C++中']'令牌之前的预期主表达式
- 错误:令牌之前的预期主表达式'&&'
- 令牌之前']'预期的主表达式?
- 循环依赖项 '{'令牌之前的预期类名