简体   繁体   中英

Const method with new c++ return value syntax

it's a simple question but i don't find answer.

I start to work with the new c++ return value syntax. For example :

class A
{ 
    // Old syntax
    float foo();

    // New syntax 
    auto foo() ->float;
};

But i don't know how to do the same thing for const method

class A
    { 
        // Old syntax
        float foo() const;

        // New syntax 
        auto foo() ->float const;
    };

Always detecting as returning const float. If someone know how to write correctly this kind of method, thank you in advance.

auto foo() const -> float; is the syntax.

The return type is float , not const float , and the function itself is a const member.

Note that you are allowed to use one format in the declaration and the other in the definition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM