Jzk Jzk - 3 months ago 8
C++ Question

Why is std::regex not a valid type?

Say I have the following code:

class.h

#ifndef CLASS_H
#define CLASS_H

class Class
{
private:
std::regex* regex;
};

#endif


class.cpp

#include <regex>
#include "class.h"
// ...


Compiling this results in the following error:

error: "regex" in namespace "std" does not name a type
std::regex* regex;
^~~~~


I am however able to use the std::regex library in any other manner?
Running on GCC 6.1.1. Also tried to compile explicitly with the -std=C++11 flag.

Answer
#ifndef CLASS_H
#define CLASS_H

#include <regex>

class Class
{
    private:
        std::regex* regex;
};

#endif

Works fine if you actually include the library in your class.

Example