以下代码摘自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>();