2

I asked this question yesterday and thought I got to the bottom of the problem... But alas it seems to be something else. I haven't the faintest idea what the issue could be, but this error is being thrown using the the following code:

Error:

a2main.cpp:36:21: error: no member named 'readJSON' in namespace 'json'
        out = json::readJSON(data_dir + "a2-empty_object.json", e, debug);
              ~~~~~~^

main.cpp

#include <iostream>
#include <string>
#include "Object.h"

int main(){

std::string out;

        out = json::readJSON(data_dir + "a2-empty_object.json", e, debug);

}

Object.h

#ifndef _JSON_READER_H_
#define _JSON_READER_H_

namespace json{

    enum JSON_TYPE {
        UNKNOWN, EMPTY, ARRAY_OPEN, ARRAY_CLOSE, OBJECT_OPEN, OBJECT_CLOSE, NV_PAIR
    };

    std::string trim(const std::string& str);
    std::string trim(const std::string& str, char c);
    std::string getName(const std::string& str);
    std::string getValue(const std::string& str);
    JSON_TYPE get_json_type(std::string s);

    template<typename T>
    List <T, OBJECTS_PER_JSON_FILE>* deserializeJSON(std::string filename, T obj, bool debug) {

        std::ifstream fin(filename);
        if (fin.fail()){
            throw std::string("Couldn't open: " + filename);
        }


        std::string fline, line, n,v;
        bool done=false;

        auto list = new List <T, OBJECTS_PER_JSON_FILE>();

        return list;
    }


    template<typename T>
    std::string readJSON(std::string jsonFile, T& object, bool debug = false, char delimiter = ',') {
        std::string string_of_values = "test";

        return string_of_values;
    }

}

#endif

Why is it throwing an error that the function is not in the namespace? It seems rather odd. Could it be a template issue? Thanks!

EDIT:

In file included from a2main.cpp:13:
./JSONReader.h:60:2: error: unknown type name 'List'
        List <T, OBJECTS_PER_JSON_FILE>* deserializeJSON(std::string filename, T obj, bool debug) {
        ^
./JSONReader.h:60:7: error: expected unqualified-id
        List <T, OBJECTS_PER_JSON_FILE>* deserializeJSON(std::string filename, T obj, bool debug) {
             ^
Kris
  • 8,866
  • 6
  • 24
  • 44
  • 1
    what is 'e' ? you have in the call, but seems not to be declared? – AndersK Nov 09 '14 at 20:56
  • Could you try doing `readJSON(data_dir ...)` where `Type` is the type of passed in object (`e`)? – mmtauqir Nov 09 '14 at 20:56
  • The variables are all declared, I just trimmed a bit of the fat. Its simply not seeing the function in the namespace, but its clearly there. – Kris Nov 09 '14 at 20:57
  • I could give it a go! EDIT: Throwing in the type doesn't seem to solve it either... – Kris Nov 09 '14 at 20:57
  • You are using a reserved name `_JSON_READER_H_` (see [here](http://stackoverflow.com/q/228783/509868) for details); maybe it conflicts with some names elsewhere? Try removing the leading underscore from the name. – anatolyg Nov 09 '14 at 21:03
  • @anatolyg That's for identifiers though ... not for pre-processor ... – mmtauqir Nov 09 '14 at 21:06
  • Adjusting the preprocessor did not work :/ – Kris Nov 09 '14 at 21:07
  • Could you try using a different namespace? I think that namespace might already be in use. EDIT: Actually, nvm. – mmtauqir Nov 09 '14 at 21:08
  • I get the same error just with the new namespace name. Its so weird. – Kris Nov 09 '14 at 21:09
  • I just "reproduced" your case here with this: http://sprunge.us/NKMS It's compiling and running just fine. – mmtauqir Nov 09 '14 at 21:10
  • Your code seems to compile fine. I wonder if the namespace is ending before it hits the readJSON function. I searched for a curly out of place but that doesn't seem to be it. If I remove the deserializeJSON function all together, the problem disappears. I just get an error that deserializeJSON is undefined when its called in readJSON. – Kris Nov 09 '14 at 21:13
  • How are you compiling your code? – mmtauqir Nov 09 '14 at 21:16
  • g++ main.cpp -std=c++11 – Kris Nov 09 '14 at 21:16
  • Try moving readJSON before deseralizeJSON ... maybe that will help show the problem with deserializeJSON ... I am just throwing ideas out there ... – mmtauqir Nov 09 '14 at 21:20
  • I did that and the problem vanished. I updated the main post to show you the errors thrown by the deserializer. – Kris Nov 09 '14 at 21:24
  • Have you included the right headers for List type? – mmtauqir Nov 09 '14 at 21:25
  • I'll see if I can figure it out. – Kris Nov 09 '14 at 21:39
  • What happens if you copy-paste the contents of Object.h into main.cpp? `#include` is just text replacement after all. – David G Nov 09 '14 at 21:53

0 Answers0