Kla*_*aus 1 c++ templates rvalue-reference c++11
我有重载方法:
template<typename AnyType>
void AnyFunc(AnyType &t);
template<typename AnyType>
void AnyFunc(AnyType &&t);
Run Code Online (Sandbox Code Playgroud)
我有一个调用程序,它持有一个指针,并希望使用其中一个函数:
MyType* ptr=new MyType();
AnyFunc(*ptr);
Run Code Online (Sandbox Code Playgroud)
最后一行遇到编译错误:AnyFunc的模糊重载
如何选择我需要的功能?简单的例子是使用:
AnyFunc(std::move(*ptr));
Run Code Online (Sandbox Code Playgroud)
选择void AnyFunc(AnyType &&t);但这不是我想要的.我需要这个
void AnyFunc(AnyType &t);方法.
| 归档时间: |
|
| 查看次数: |
463 次 |
| 最近记录: |