C++ 循环依赖项在';之前应为类名;{';代币
很抱歉提前启动了另一个循环依赖线程,但我尝试了几乎所有的方法,也许一双新的眼睛可以帮上忙。 我如何编译这个 卡片C++ 循环依赖项在';之前应为类名;{';代币,c++,circular-dependency,C++,Circular Dependency,很抱歉提前启动了另一个循环依赖线程,但我尝试了几乎所有的方法,也许一双新的眼睛可以帮上忙。 我如何编译这个 卡片 #ifndef CARD_H #define CARD_H #include <string> #include <sstream> #include <irrKlang.h> #include "Database.h" using namespace std; using namespace irrklang; class Card: pu
#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:
\ifndef卡
#定义卡片
#包括
#包括
#包括
#包括“Database.h”
使用名称空间std;
使用名称空间irrklang;
类卡:公共数据库{//问题在“{”标记之前应为类名
公众:
数据库.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);
\ifndef\uu数据库__
#定义数据库__
#包括
#包括
#包括
#包括
#包括
#包括
#包括“Card.h”//即使我包括Card.h
使用名称空间std;
使用名称空间irrklang;
class Card;//如果我去掉它,我会得到:'Card'未在此范围内声明|
类数据库
{
公众:
向量查询(wstring查询);
两条规则有助于防止循环依赖:
1.)如果不需要类的实现,请仅通过前向引用声明它。
2.)如果需要实现,请尽可能晚地包含头文件
卡片
#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
Database.cpp
#include "Database.h"
Database database;
卡
继承了数据库
?听起来一点也不正确。这似乎是一个语法错误,因为缺少了simicolon或括号,所以显示可报告代码的代码片段就更好了。。。。
#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