When I was trying to build the Google test c project I caught the errors
Error C3861 't1': identifier not found
Error C2065 't1': undeclared identifier
Error C2039 'thread': is not a member of 'std'
Error C2065 'thread': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 't1'
My test code is:
#include <future>
#include <thread>
#include "pch.h"
TEST(...)
{
// preconditions here
std::thread t1([&] {
Sleep(100);
testee.enqueue(item);
});
t1.join();
// other logic
}
Why I cannot use the std::thread and other C 11 features in my project? How can I do it?
CodePudding user response:
Why I cannot use the std::thread and other C 11 features in my project?
Potential reason 1: You cannot use C 11 features unless you use C 11 or a later standard.
Potential reason 2: You cannot use std::thread
unless you include the header that defines std::thread
. It's defined in the header <thread>
.
CodePudding user response:
#include "pch.h"
must be first. Other #include directive prior #include "pch.h"
are ignored.