我有一个标题文件“check.h
”,用于定义以下struct
:
#ifndef CHECK_H
#define CHECK_H
#include<string>
struct Test{
std::string check;
};
#endif
我有另一个头文件“test.h
”,它具有以下函数,返回类型为上面定义的struct Test
:
#ifndef TEST_H
#define TEST_H
#include<string>
#include "check.h"
Test display(std::string);
#endif
但即使在此标头文件中包含"check.h"
,我也会收到unable to resolve identifier
错误。我该怎么做才能解决这个问题?
答案 0 :(得分:2)
只要您没有定义名称为Test
的其他内容(例如变量或函数),您的代码就可以了。
如果你有,那么你需要明确指出你是指班级而不是其他东西:
struct Test display(std::string);
^^^^^^
虽然更好的解决方案是避免对不同的东西使用相同的名称。
答案 1 :(得分:0)
您应该返回struct Test
,因为test.h
定义的结构不是类型。
或者只是将结构定义更改为typedef:
typedef struct s_Test{
string check;
} Test;
请参阅维基百科there