在下面的代码中,我收到错误。我在做什么?
regex.cpp:11:错误:字符串常量之前的预期标识符
regex.cpp:11:错误:在字符串常量之前预期','或'...'
#include <boost/regex.hpp>
#include <iostream>
#include <string>
class RH
{
public:
bool matches(const std::string & str);
private:
boost::regex regex_("\\d:\\d-\\d:\\d"); // this is where error points to
};
答案 0 :(得分:4)
你必须在构造函数中初始化:
class RH {
...
public:
RH() : regex_("\\d:\\d-\\d:\\d") {}
...
private:
boost::regex regex_;
}