Search code examples
c++structheadermutex

'mutex': is not a member of 'std' error in msvc


The following code which resides in one of my header files produces the error. There was no problem when the mutex was in a source file and I was using it with extern as a global variable. Thank you!

#include <memory>

struct MyStruct
{
    std::mutex m;
};

Solution

  • you want include the file where std::mutex is located at, in <mutex>

    #include <mutex>
    
    struct MyStruct
    {
        std::mutex m;
    }