Mmm Donuts
Mmm Donuts

Reputation: 10285

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

Upvotes: 6

Views: 22727

Answers (2)

Sahand Kamal
Sahand Kamal

Reputation: 1

#include

//that will fix the error %100

Upvotes: -2

srossi
srossi

Reputation: 132

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.

Upvotes: 4

Related Questions