问题描述:

I get this error, porting code from C to C++:

src/common/atom.cpp:19:8: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11

void Atom::Run(ThreadFunction threadFunction)

{

mutex = PTHREAD_MUTEX_INITIALIZER;

if(threadFunction!=NULL)

{

pthread_create(&threadID, NULL, threadFunction, this);

this->running=true;

}

}

Why do I need this flag in C++ but not in C, and what are initializers?

网友答案:

Problem

src/common/atom.cpp:19:8: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11

Solution

As you can see in the error, it tells you to have the flags:

std=c++11 or -std=gnu++11

This is so you have version C++11. Initalizer lists require C++11 .

With the version of C++11, you have many additional features like Lambda Expressions, Automatic Type Deduction and decltype, Uniform Initialization Syntax, Deleted and Defaulted Functions, nullptr, Rvalue References, New Smart Pointer Classes (shared_ptr, unique_ptr), C++11 Standard Library, More C++ Algorithms, and much more!

References

C++11 FAQ - Bjarne Stroustrup

相关阅读:
Top