Originally Posted by
Evil g++
In file included from main.cpp:3:0:
scope.h: In function ‘double mm::get_num(const string&, const mm::scope<std::basic_string<char> >&)’:
scope.h:40:30: error: passing ‘const mm::scope<std::basic_string<char> >’ as ‘this’ argument of ‘T* mm::scope<T>::find(const string&) [with T = std::basic_string<char>, std::string = std::basic_string<char>]’ discards qualifiers [-fpermissive]
make: *** [main.o] Error 1
main.cpp has nothing important now...
Here is the scope.h
Code:
#ifndef SCOPE
#define SCOPE
#include<vector>
#include<map>
#include<sstream>
namespace mm
{
template<typename T>
class scope
{
std::vector< std::map<std::string,T> > data;
public:
T* find(const std::string& s)
{
for(auto m=data.rbegin();m!=data.rend();m++)
{
auto p = m->find(s);
if(p!=m->end())return &(p->second);
}
return nullptr;
};
void new_local(const std::map<std::string,T>& sm){data.push_back(sm);};
void exit_scope(){data.pop_back();};
};
/*Converts a string to a double
* If the string is an identifier....
* it fetches the value from the scope object supplied.
*/
double get_num(const std::string& s, const scope<std::string>& ss)
{
std::string numstr;
std::istringstream is(s);
double d;
if(is>>d)
return d;
else
{
std::string* x = ss.find(s);
if(x!=nullptr)numstr=*x;
else throw("NAN");//change later
}
is.str(numstr);
if(is>>d)
return d;
else throw("NAN");//change later
}
}
#endif