我在main 中声明了以下结构(NEVERMIND THE MEMBERS!):
struct args
{
std::vector<string> names;
std::vector<std::shared_ptr<RegularExpression>>vreg;
std::vector<string> stopFile;
std::vector<string> groundTruth;
int debug;
};
我有一个classe Verification,它将args作为构造函数参数
#ifndef VERIFICATION_H
#define VERIFICATION_H
class Verification
{
public:
Verification(std::string, std::vector<double>,double,args);
private:
args _A;
}
#endif // VERIFICATION_H
现在主要:
struct args
{
std::vector<string> names;
std::vector<std::shared_ptr<RegularExpression>>vreg;
std::vector<string> stopFile;
std::vector<string> groundTruth;
int debug;
};
int main()
{
Verification v("res.cr",gt, 0.75,A);
return 0;
}
我有以下编译错误:
如何在类验证中使用main中声明的结构作为构造函数参数?
谢谢。
答案 0 :(得分:2)
必须以Verification类翻译单元可见的方式定义结构。我建议你将结构移动到它自己的头文件,并在你的主文件和Verification.h中#include它。
答案 1 :(得分:2)
第一个错误是编译class Verification
时编译器必须首先看到struct args
。它不知道你以后要定义struct args
。
简单的解决方法是将struct args
的定义移至Verification.h
。
修复此问题但你仍然会遇到其他错误(最明显的是A
没有定义),但是当你到达它们时我们可以处理这些错误。
答案 2 :(得分:1)
您的第二个错误是由于字符串文字是const char[]
而不是std::string
这一事实 - 您需要在将string
传递给期望字符串的函数之前创建gt
此外,还需要在此次调用之前定义A
和{{1}}。