我昨天问了这个问题,并认为我已经解决了问题的根源......但是唉,这似乎是另一回事。我不知道问题是什么,但是使用以下代码抛出了这个错误:
错误:
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
为什么抛出函数不在命名空间中的错误?这看起来很奇怪。这可能是模板问题吗?谢谢!
编辑:
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) {
^