volatile overloading?

后端 未结 3 1581
面向向阳花
面向向阳花 2020-12-29 12:24

I heard that volatile is factor of overloading like const.

If a function is overloaded by volatile parameter, when is the volatile-version called?

I can\'t i

3条回答
  •  爱一瞬间的悲伤
    2020-12-29 12:38

    Write a test program to find out.

    void func(const int& a)
    {
        std::cout << "func(const)" << std::endl;
    }
    
    void func(const volatile int& a)
    {
        std::cout << "func(const volatile)" << std::endl;
    }
    
    int main()
    {
        const int a = 0;
        const volatile int b = 0;
        func(a);
        func(b);
        system("pause");
        return 0;
    }
    

    will output:

    func(const)
    func(const volatile)
    

提交回复
热议问题