基本上我有两个抽象类IVisitor
和IVisitable
,Product
和Order
正在扩展IVisitable
而报告正在扩展IVisitor
,所以Report
可以访问Order
和Product
并计算订单或产品的数量。
我得到一些我无法解决的错误,例如"函数不带一个参数"当显然,未知标识符等。
以下是代码:
IVisitable.h
#pragma once
#include"IVisitor.h"
class IVisitable{
public:
virtual void accept(IVisitor *v)=0;
};
IVisitor.h
#pragma once
#include"Product.h"
#include"Order.h"
class IVisitor{
public:
virtual void visit(Order*)=0;
virtual void visit(Product*)=0;
};
Order.h
#pragma once
#include<string>
using namespace std;
#include<vector>
#include"Product.h"
class Order : public IVisitable{
public:
vector<Product> list;
void accept(IVisitor *v){
v->visit(this);
for(int i=0; i<list.size(); i++)
list[i].accept(v);
}
};
Product.h
#pragma once
#include<string>
using namespace std;
#include"IVisitable.h"
class Product : public IVisitable{
public:
string name;
Product(string i){name = i;}
Product(){}
void accept(IVisitor *v){
v->visit(this);
}
};
Report.h
#pragma once
#include"IVisitor.h"
class Report : public IVisitor{
public:
int numProduct;
int numOrders;
Report(){
numProduct = numOrders = 0;
}
void visit(Order*){
numOrders++;
}
void visit(Product*){
numProduct++;
}
};
Source.cpp
#include<iostream>
#include"Order.h"
#include"Report.h"
using namespace std;
void main(){
Product p1("eggs");
Product p2("meat");
Product p3("milk");
Order ord1;
ord1.list.push_back(p1);
ord1.list.push_back(p2);
ord1.list.push_back(p3);
Report *report = new Report;
ord1.accept(report);
cout<<report->numProduct<<endl;
}
错误:
1>ivisitor.h(7): error C2061: syntax error : identifier 'Order'
1>ivisitor.h(8): error C2061: syntax error : identifier 'Product'
1>ivisitor.h(8): error C2535: 'void IVisitor::visit(void)' : member function already defined or declared
1>ivisitor.h(7) : see declaration of 'IVisitor::visit'
1>product.h(13): error C2660: 'IVisitor::visit' : function does not take 1 arguments
1>order.h(13): error C2660: 'IVisitor::visit' : function does not take 1 arguments
1>order.h(15): warning C4018: '<' : signed/unsigned mismatch
1>source.cpp(17): error C2259: 'Report' : cannot instantiate abstract class
1> due to following members:
1> 'void IVisitor::visit(void)' : is abstract
答案 0 :(得分:2)
头文件之间有一个引用周期。 要解决问题,请不要使用
SELECT id,min((arr ->> 2)::numeric) AS custom_value
FROM (
SELECT id, jdoc
FROM table,
jsonb_each(column1) d (key, jdoc)
) sub,
jsonb_each(jdoc) doc (key, arr)
group by 1
但请使用
#include "..."