简体   繁体   中英

No member named 'name' in namespace 'namespace'

I can't for the life of me figure out why this error is being generated as I'm pretty sure the syntax is correct (obviously I'm wrong!). So I figured I'd see if anyone here could point it out for me.

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 = ',') {}
}

I'm basically getting this error, when clearly the function is in the namespace. Why does it refer to the function as a member? Maybe there is something else going on here...

Error:

a2main.cpp:66:21: error: no member named 'readJSON' in namespace 'json'
        out = json::readJSON(data_dir + "a2-cartoons.json", c, debug, '|');

You are probably not including the header files correctly.

The following code compiles (with both clang and gcc) and runs fine

#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;
}

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM