我想知道,在以下法典中是否有任何办法区分职能要求(阵列作为参数):
#include <cstring>
#include <iostream>
template <size_t Size>
void foo_array( const char (&data)[Size] )
{
std::cout << "named
";
}
template <size_t Size>
void foo_array( char (&&data)[Size] ) //rvalue of arrays?
{
std::cout << "temporary
";
}
struct A {};
void foo( const A& a )
{
std::cout << "named
";
}
void foo( A&& a )
{
std::cout << "temporary
";
}
int main( /* int argc, char* argv[] */ )
{
A a;
const A a2;
foo(a);
foo(A()); //Temporary -> OK!
foo(a2);
//------------------------------------------------------------
char arr[] = "hello";
const char arr2[] = "hello";
foo_array(arr);
foo_array("hello"); //How I can differentiate this?
foo_array(arr2);
return 0;
}
“功能家庭”能够区分一个临时物体和一个指定物体。 不是 f。
Is it possible in C++11 ? If not, do you think could be possible? (obviously changing the standard)
Regards. Fernando.