As suggested in https://stackoverflow.com/a/44884240/3782963. I created a method of return type std::map<std::string, Spikes::data> get_data1(). I create a struct called data:
struct data {
std::vector<Eigen::MatrixXd> samples;
std::vector<std::string> sample_names;
int index = -1;
};
and placed it in my namespace and out of the class FileReader.
My method looks like:
std::map<std::string, Spikes::data> FileReader::get_data1() {
std::map<std::string, Spikes::data> content;
std::vector<Eigen::MatrixXd> samples;
std::vector<std::string> sample_names;
for (auto i : list_dir()) {
if (contains_number(i)) {
samples.push_back(load_csv(location + "/" + i));
sample_names.push_back(i);
}
}
content.emplace(std::make_pair("samples", Spikes::data{samples,0}));
content.emplace(std::make_pair("sample_names", Spikes::data{sample_names,1}));
return content;
And in my main.cpp I am calling this method as:
for (auto i:a.get_data1()["samples"].samples){
std::cout<<i;
}
But I get the following errors:
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.cpp: In member function 'std::map<std::basic_string<char>, Spikes::data> Spikes::FileReader::get_data1()':
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.cpp:154:69: error: no matching function for call to 'Spikes::data::data(<brace-enclosed initializer list>)'
content.emplace(std::make_pair("samples", Spikes::data{samples,0}));
^
In file included from /cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.cpp:3:0:
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate: Spikes::data::data()
struct data {
^
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate expects 0 arguments, 2 provided
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate: Spikes::data::data(const Spikes::data&)
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate expects 1 argument, 2 provided
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate: Spikes::data::data(Spikes::data&&)
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate expects 1 argument, 2 provided
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.cpp:155:79: error: no matching function for call to 'Spikes::data::data(<brace-enclosed initializer list>)'
content.emplace(std::make_pair("sample_names", Spikes::data{sample_names,1}));
^
In file included from /cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.cpp:3:0:
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate: Spikes::data::data()
struct data {
^
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate expects 0 arguments, 2 provided
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate: Spikes::data::data(const Spikes::data&)
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate expects 1 argument, 2 provided
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate: Spikes::data::data(Spikes::data&&)
/cygdrive/c/Users/aksha/Box Sync/MyDrive/Projects/Akshay-GitHub/libSpikes/libSpikes/src/Core/FileReader.h:13:12: note: candidate expects 1 argument, 2 provided
I have no clue as to what is going on.
I have even tried doing:
content["samples"] = Spikes::data{samples,0};
content["sample_names"] = Spikes::data{sample_names,1};
I still get the same error. Any help would be highly appreciated.