简体   繁体   English

是否有可能在编译时不知道模板类型

[英]Is it possible to have a templated type not known at compile time

Suppose I have a class: 假设我有一堂课:

template <unsigned M, unsigned N, typename T = float>
class Matrix
{};

I want to read from a file which contains matrices of some unknown M,N and create the above type: 我想从包含某些未知M,N矩阵的文件中读取并创建上述类型:

Matrix getMatrixFromFile(std::string &path); 矩阵getMatrixFromFile(std :: string&path);

Is this possible given that M, N are not known at compile time? 鉴于在编译时不知道M,N,这可能吗?

The answer is no. 答案是不。

The templates parameters are used to create types at compile time based on the types passed. 模板参数用于在编译时根据传递的类型创建类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模板化函数编译时返回类型,无参数 - Templated function Return type at compile time no arguments 在模板类型上编译时间循环 - compile time loop over templated type 是否可以检查编译时是否知道const值? - Is it possible to check if const value is known at compile time? 从编译时已知的字符串中检索类型 - Retrieve a type from a string known at compile time 当非类型参数值在运行时已知时声明模板化 class object:运算符 + 模板化 class 中的重载 - Declare templated class object when non type argument value to be known at run time : operator + overloading in templated class 在编译时确定模板化函数的结果类型? - Determine type of templated function result at compile-time? 有没有办法在编译时从模板化方法中存储参数的类型? - Is there a way to store argument's type from templated method at compile time? 如何在编译时访问模板化类的模板类型? - How to access a template type of a templated class at compile time? 类型在编译时已知的虚拟方法 - Virtual methods whose type is known at compile-time 可以通过编译时已知的 object 创建(或模板实例化)类型吗? - Can type be created(or template instantiated) by object known at compile time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM