c++ - C++17 typealias removes the ability of class template argument deduction
问题描述
The C++17 class template argument deduction works just fine, but I am not able to create a type alias on such a type, where the class template argument deduction works.
Are there any special tweaks to using needed, that it works?
Here I have a minimal working example:
#include <utility>
template <typename T>
class cls {
public:
cls(T&& arg) : val(std::forward<T>(arg)) {}
private:
T val;
};
template <typename T>
using alias = cls<T>;
int main() {
cls c(1);
//alias b(2); //not working, but why?
alias<int> a(2);
}
This code should compile with g++8 and --std=c++17, but if I uncomment the commented line, I get the following error:
test.cpp:16:11: error: missing template arguments before ‘b’
alias b(2);//not working
解决方案
推荐阅读
- c++ - 使用对数据类型向量的哈希表中的分段错误错误
- node.js - 使用 NVM 找不到 Typescript
- javascript - 如何从字符串中删除 type="text/css" 属性?
- excel - 在 .Find 方法上获取 Object required 错误
- apache-kafka - 如何在融合的 kafka 休息代理中访问主题的最新偏移量以计算滞后
- java - 找不到参数的方法 implementation() [com.google.firebase:firebase-core:17.0.0]
- javascript - axios正常GET请求进度
- json - 通过 jq 将 aws cli 解析为 CSV
- python - 损坏的 JPEG 数据:标记 0xdb OpenCV 与 macOS Mojave 之前的 20 个无关字节
- centroid - 从几何形状字段创建质心列会产生 AttributeError: 'NoneType' object has no attribute 'centroid'