假设我有以下代码:
class.h
#ifndef CLASS_H
#define CLASS_H
class Class
{
private:
std::regex* regex;
};
#endif
类.cpp
#include <regex>
#include "class.h"
// ...
编译会导致以下错误:
error: "regex" in namespace "std" does not name a type
std::regex* regex;
^~~~~
然而,我能够以任何其他方式使用 std::regex 库吗? 在 GCC 6.1.1 上运行。还尝试使用 -std=C++11 标志显式编译。
最佳答案
#ifndef CLASS_H
#define CLASS_H
#include <regex>
class Class
{
private:
std::regex* regex;
};
#endif
如果你真的在你的类(class)中包含这个库,效果很好。
关于c++ - 为什么 std::regex 不是有效类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39402248/