我想知道你们是否可以帮助我解决一些我在下面评论过的错误。我不相信我已经有这么多了。
class CalculusWizard
{
private:
const static char varChars[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; // error: a brace-enclosed initializer is not allowed here before '{' token, error: invalid in-class initialization of static data member of non-itegral type 'const char[]'
const static size_t varCharsLen = sizeof(varChars) / sizeof(const char);
const static enum functop = {NONE, PLUS, MINUS, TIMES, DIVIDE, COMPOSITION}; // error: use of enum 'functop' without previous declaration, error: unexpected qualified-id before '=' token
bool isVariable(const char &);
public:
CalculusWizard();
~CalculusWizard();
std::string derivative(std::string &, const char &, unsigned &);
};
bool CalculusWizard::isVariable(const char & c)
{
char * thisptr = varChars; // error: 'varChars' was not declared in this scope
char * offend = varChars + varCharsLen;
while (thisptr != offend)
if (*thisptr++ == c)
return true;
return false;
/*
Alternatively, return c >= 'a' && c <= 'z'
}
另外,有没有更好的方法来做我尝试varChars
的事情?关键是,我需要一个CalculusWizard
的每个实例引用的字符数组。我认为私人static
成员是可行的方式。