Android NDK's c++11 standard support

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.