1

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

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

1 回答 1

4

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

class RH {
...
public:
    RH() : regex_("\\d:\\d-\\d:\\d") {}
...
private:
    boost::regex regex_;
}
于 2013-05-26T18:33:56.940 回答