[英]No member named 'name' in namespace 'namespace'
我一生无法弄清楚为什么会生成此错误,因为我非常确定语法是正确的(显然我错了!)。 因此,我想知道这里是否有人可以为我指出这一点。
main.cpp中
#include "Object.h"
int main(){
out = json::readJSON(data_dir + "a2-empty_array_with_empty_object.json", e, debug);
}
Object.h
namespace json{
template<typename T>
std::string readJSON(std::string jsonFile, T& object, bool debug = false, char delimiter = ',') {}
}
当函数明显在名称空间中时,我基本上会收到此错误。 为什么将函数称为成员? 也许这里还有其他事情...
错误:
a2main.cpp:66:21: error: no member named 'readJSON' in namespace 'json'
out = json::readJSON(data_dir + "a2-cartoons.json", c, debug, '|');
您可能没有正确包含头文件。
以下代码编译(同时使用clang和gcc)并正常运行
#include <string>
namespace json
{
template<typename T>
std::string readJSON(std::string jsonFile, T& object, bool debug = false, char delimiter = ',')
{
return "Hello"; //This function should return a string
}
}
int main()
{
std::string data_dir = "test-";
int e = 3;
bool debug = false;
std::string out = json::readJSON(data_dir + "a2-empty_array_with_empty_object.json", e, debug);
return 0;
}
我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.