[英]error C2059: syntax error : '.'
I am trying to get this function to work, but I keep getting 我正在尝试使此功能正常工作,但我一直在
error C2059: syntax error : '.' 错误C2059:语法错误:“。”
on the lines of the two declare() function bodies where I call is_declared, and I can't figure it out. 在我调用is_declared的两个define()函数体的行上,我无法弄清楚。 I know it has to do with is_declared, but I am having trouble. 我知道这与is_declared有关,但是我遇到了麻烦。
class Variable {
public:
std::string name;
double value;
char type;
Variable(std::string n, double v) :name(n), value(v), type('v') { }
Variable(std::string n, double v, char a) :name(n), value(v), type('c') { }
};
class Symbol_table {
public:
Symbol_table();
double get(std::string s);
void set(std::string s, double d);
bool is_declared(std::string s);
double declare(std::string var, double val);
double declare(std::string var, double val, char c);
private:
std::vector<Variable> var_table;
};
Symbol_table::Symbol_table() {}
double Symbol_table::get(std::string s)
{
for (int i = 0; i<var_table.size(); ++i)
if (var_table[i].name == s) return var_table[i].value;
error("get: undefined name ",s);
}
void Symbol_table::set(std::string s, double d)
{
for (int i = 0; i<=var_table.size(); ++i)
if (var_table[i].name == s) {
if (var_table[i].type == 'c') error("set_value: Cannot change a constant's value");
var_table[i].value = d;
return;
}
error("set: undefined name ",s);
}
double Symbol_table::declare(std::string var, double val)
{//error here
if (Symbol_table.is_declared(var)) error(var," declared twice");
var_table.push_back(Variable(var,val));
return val;
}
double Symbol_table::declare(std::string vari, double valu, char c)
{//error here
if (Symbol_table.is_declared(vari)) error(vari," declared twice");
var_table.push_back(Variable(vari,valu,c));
return valu;
}
bool Symbol_table::is_declared(std::string s)
{
for (int i = 0; i<var_table.size(); ++i)
if (var_table[i].name == s) return true;
return false;
}
The syntax Symbol_table.is_declared
is not valid C++ in that context. 在这种情况下,语法Symbol_table.is_declared
无效的C ++。 Most likely you meant to write 您最有可能打算写
if (this->is_declared(var)) error(var," declared twice");
You can also omit the this->
if you prefer, that's a matter of style. 如果愿意,也可以省略this->
,这是样式问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.