相关疑难解决方法(0)

const临时从模板类型和为什么使用std :: add_const?

以下代码摘自cppreference.com.

#include <iostream>
#include <type_traits>

struct foo
{
    void m() { std::cout << "Non-cv\n"; }
    void m() const { std::cout << "Const\n"; }
};

template <class T>
void call_m()
{
    T().m();
}

int main()
{
    call_m<foo>();
    call_m<std::add_const<foo>::type>();
}
Run Code Online (Sandbox Code Playgroud)

但是,使用VC++ 2012年11月的CTP编译时,输出为

非CV

非CV

而不是预期的:

非CV

常量

此外,以下两个陈述之间的区别是什么:

call_m<const foo>();

call_m<std::add_const<foo>::type>();

c++ overloading type-traits visual-c++ c++11

9
推荐指数
1
解决办法
472
查看次数

标签 统计

c++ ×1

c++11 ×1

overloading ×1

type-traits ×1

visual-c++ ×1