When I was trying to call std::atomic::store in initialization list, I got following compiler error: g++ -std=c++11 test_function_call_in_ctor.cc
test_function_call_in_ctor.cc: In constructor ‘TestA::TestA()’: test_function_call_in_ctor.cc:7:17: error: expected ‘(’ before ‘.’ token TestA() : run_.store(true) { ^ test_function_call_in_ctor.cc:7:17: error: expected ‘{’ before ‘.’ token
source code as below:
class TestA {
public:
TestA() : run_.store(true) {
cout << "TestA()";
if (run_.load()) {
cout << "Run == TRUE" << endl;
}
}
~TestA() {}
private:
std::atomic<bool> run_;
};
int main() {
TestA a;
return 0;
}
Any idea on this issue? Thanks a lot.
Aucun commentaire:
Enregistrer un commentaire