无法将boost :: regex定义为私有变量

时间:2013-05-26 18:32:24

标签: c++

在下面的代码中,我收到错误。我在做什么?

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
};

1 个答案:

答案 0 :(得分:4)

你必须在构造函数中初始化:

class RH {
...
public:
    RH() : regex_("\\d:\\d-\\d:\\d") {}
...
private:
    boost::regex regex_;
}
相关问题