c++ - 为什么 std::regex 不是有效类型?

标签 c++ regex c++11 g++ libstdc++

假设我有以下代码:
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)中包含这个库,效果很好。

Example

关于c++ - 为什么 std::regex 不是有效类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39402248/

相关文章:

c++ - 这个 nm 输出 "V typeinfo name for void*"是什么意思?

c++ - 返回类型推导

c++ - 当 C++ const 方法同步可变状态时,非常量方法也必须这样做吗?

python - 如何从文本文件中提取特定部分?

algorithm - 为什么此 KMP 代码显示运行时错误?

c++ - 将左值传递给用作临时std容器的模板参数的通用引用参数时与分配器相关的错误

c++ - 如何在不使用键盘的情况下按键盘上的键?

c++ - 找不到调试符号

python - 嵌套的正则表达式字符串

javascript - 正则表达式忽略重复匹配