我正在学习C++,我正在尝试创建一个“在线商店”,在那里你可以发布文章并对它们进行评论,一条评论属于一篇文章,一篇文章可以有很多评论,但我现在不知道如何在不创建循环的情况下对其进行编码
我尝试过使用Article.hComment.h# -> "Comment.h“,反之亦然,但是当我试图编译它时,它创建了一个循环,其中A导入B,B导入A
Comment.h
#include <string>
//This is what I've tried but it creates a loop
#include "Article.h"
using namespace std;
//Class
class Comment
{
private:
Article article;
string description;
string rating;
};
Article.h
#include <string>
#include <map>
//The other part of my buggy-loop
#include "Comentario.h"
class Article
{
private:
map<string, int> art_comments;
string name;
string rating;
};
更新
谢谢大家,你给我的Resolve build errors due to circular dependency amongst classes解决了我的问题
因为这个问题已经解决得比较早了,我应该删除这篇文章吗?
https://stackoverflow.com/questions/56565958
复制相似问题