C++11 Auto

C++11 Auto,第1张

概述本文章向大家介绍C++11 Auto,主要包括C++11 Auto使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

// auto.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。

//

#include "pch.h"

#include

#include

#include

using namespace std;

class Foo

{

public :

    static int get(voID)

    {

        return 0;

    }

};

class bar 

{

public:

    static const char* get(voID)

    {

        return "0";

    }

};

template

voID func(voID)

{

    auto val = A::get();

}

int main()

{

    auto  x = 5;                    // OK: x==> int 

    auto pi = new auto(1);            // OK: pi==>int*

    const auto *v = &x,u = 6;        //OK: v ==>const int*,u==>const int 

    static auto y = 0.0;            //OK: y ==>double

    // auto int r ; error

    // auto s; error

    int xx = 0;

    auto* a = &xx;    //a==>int*,auto==>int

    auto b = &xx;    //b==>int*,auto==>int*

    auto &c = xx;    //c==>int&,auto==>int

    auto d = c;        //d==>int,auto==>int

    const auto e = xx;    //e==>const int 

    auto f = e;            //f==>int

    const auto& g = xx;        //g==>const int&

    auto& h = g;            //f==>const int&

    //auto limits

    //1.can't be a parameter of a function

    //2.can't be used in a non-static variable member

    //3.can't define an array

    //4.can't infer the template's parameter

    // stl container example

    /*

    map resMap;

    map::iterator it = resMap.begin();

    for (;it != resMap.end();++it)

    {

    }

    */

    mapresMap;

    for (auto it=resMap.begin();it != resMap.end();++it)

    {

    }

    /*

    unordered_multimapresultMap;

    unordered_multimap::iterator range = resultMap.equal_range(key);

    */

    unordered_multimapmap;

    //auto range = map.equal_range(key);

    // a new sample auto simple the function

    func();

    func();

    return 0;

}

总结

以上是内存溢出为你收集整理的C++11 Auto全部内容,希望文章能够帮你解决C++11 Auto所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1264489.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存