我需要评估一个字符串,以便为类变量赋值:
班级 :
class DATACLASS {
public:
double variable1, variable2, variable3;
};
无效的 init() :
void init()
{
DATACLASS *d = new DATACLASS;
std::string ssList[3] = {"variable1",
"variable2",
"variable3"};
for(unsigned i = 0; i < 3; ++i)
{
std::stringstream ss;
ss << ssList[i];
//ss.str().c_str() correspond to "variable1", "variable2", "variable3"
mxArray *array_ptr = mexGetVariable("base", ss.str().c_str());
double pr = (double)mxGetPr(array_ptr)[0];
// How to make the same thing here?
// I would like to have something that would evaluate
// data->ssList[i] = pr;
// or more precisely
// data->variable1 = pr;
// but from the ss string like below (but this doesn't work)
data->ss.str().c_str() = pr;
}
尝试这样做时出现这种错误:
error C2039: 'ss' : is not a member of 'DATACLASS'