Comments (3)
Hi.
Define a copy constructor and an assignment operator:
interpreter.h
explicit
Interpreter();
~Interpreter();
Interpreter(const Interpreter&);
Interpreter& operator=(const Interpreter&);
.
.
interpreter.cpp
Interpreter::Interpreter() {
m_d = new InterpreterImpl();
}
Interpreter::~Interpreter() {
delete m_d;
}
Interpreter::Interpreter(const Interpreter& other) {
m_d = new InterpreterImpl();
*m_d = *other.m_d;
}
Interpreter& Interpreter::operator=(const Interpreter& other){
if (this->m_d != other.m_d)
*m_d = *other.m_d;
return *this;
}
.
.
And your example would be:
class Programmer {
public:
Programmer() {
cmdline.addOperator("=", [](string& leftOpd, string& rightOpd) ->string {
leftOpd = rightOpd;
return leftOpd;
}, 10);
cmdline.addFunction("summ", [](const vector<string>& args) ->string {
string res;
for (auto& v : args) {
res += v;
}
return res;
});
}
Interpreter cmdline;
};
class t_user {
public:
std::string name = "root";
Programmer programmer; // each user has own programmer / interpreter / environment
};
std::vector<t_user> Users;
void main(void) {
t_user tmp_user;
tmp_user.name = "user1";
Users.push_back(tmp_user); // add a t_user to Users
// Users[0] we just pushed
std::string input = "$a = summ(1, 2);";
auto res = Users[0].programmer.cmdline.cmd(input); // <------- complains here
res; // 12
}
https://github.com/Tyill/interpreter/releases/tag/1.0.4
from interpreter.
Sorry, I ask because I can comment out....
explicit
Interpreter();
~Interpreter();
// Interpreter(const Interpreter&) = delete; // <----- comment out compiles, but segfaults
Interpreter& operator=(const Interpreter&) = delete;
if I comment out the delete line above from interpreter.h
(because the compiler complained about deleted function) it compiles but segfaults on attempt to use.
I probably dumb in how I'm approaching
from interpreter.
Thanks so much, it makes sense now :) Thanks for your help.
from interpreter.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interpreter.