-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Instances? [question] #1
Comments
Sorry, I ask because I can comment out....
if I comment out the delete line above from I probably dumb in how I'm approaching |
Hi. 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
} |
Thanks so much, it makes sense now :) Thanks for your help. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tyill,
I am wondering, not being fluent, can there be multiple instances of Interpreter?
My situation is I have a vector, of class
t_user
which keeps track of a individual connected users....A single connection [t_user] has a
Programmer
that contains an instance ofInterpreter
:[pseudocode]
Compiler throws a fit...
It's very much probably not your fault, I am playing with multi-user interpreters where users have own instances - but would introduce some globals for them to share also.
I just wondering multiple instances are possible or if my stupid fault?
The text was updated successfully, but these errors were encountered: