2014-11-09 88 views
0

我不能为我的生活弄清楚为什么会产生这个错误,因为我敢肯定语法是正确的(显然我错了!)。所以我想我会看看这里有没有人可以为我指出。名称空间'名称空间'中没有名为'name'的成员

的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, '|'); 
+0

请确保你已包含'#包含'适当的文件。 – 0x499602D2 2014-11-09 03:11:14

+0

我是,我已经双重和三重检查。 – Kris 2014-11-09 03:13:10

+0

您是否尝试过对模板进行排位,例如readJson ?我的第一个预感是模板问题。 – 2014-11-09 03:19:26

回答

2

你可能不正确,包括头文件。

下面的代码编译(既铛和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; 
} 

我希望这有助于。

相关问题