C++11 is already supported in the Android NDK, and this article focuses on how to add support for the C++11 standard in the NDK.
In the open source project Cocos2d-x, support for the C++11 standard has been added.
1. Modify the Application.mk file to add ndk_toolchain_version
ndk_toolchain_version=4.8
2. Add App_cppflags, support c++11 on command line editing
Then write the test function and call this function in JNI.
#include <android/log.h> #include <vector> #include <initializer_list>using namespace::std; #define Log_tag "Cachetest" #define LOGI (...) __android_log_print (android_log_info,log_tag,__va_args__) template <typename t>class Myarray{private:vector <T> M_array; Public:myarray () {} MyArray (const initializer_list<t>& IL) {//manually populate the element s of the array from Initializer_list x for (auto X:il) {//Use range-based for statement to iterate over the Eleme NTS of the initializer list m_array.push_back (x); Push them into the array manually}}void showcontent () {//old waylogi (' in old '); for (Std::vector<int>::iterato R ITR = M_array.begin (); ITR! = M_array.end (); ++ITR) {Logi ("%d", (*ITR));} Logi ("in c++11 new"); for (auto X:m_array) {//x is Readonlylogi ("%d", x);}}; void Test_cpp_new_version_11 () {Auto x = 1;//int x = 1;int *p = nullptr;//int *p = NULL; myarray<int> foo = {3, 4, 6, 9};fOo.showcontent ();}
For specific video tutorials, you can refer to the Hai Tong School Video Course < Android ndk> Development.
http://www.iotekclass.com/goods/courseDetail?goodId=83
Android NDK's c++11 standard support