在 main 中读取函数模板
Read a function template in main?
好吧,我不是一个很有经验的程序员,C++(仍在学习)我知道所有的C库。
我想出了一个问题。以下模板是什么意思,我应该如何从 main 调用拆分函数?
template <typename T, size_t len>
pair<size_t,size_t>
split(T const (& arr)[len]) {
//blah blah .. code ... blah blah
}
我知道我需要一个数组,但我如何在模板中传递它?我需要什么参数?
这是我在 main 中创建的数组
int N = 10;
int *array = new int[N];
//now I use I/O to pass the numbers in the array, but say we have them
//Now I should call the template. I need to pass the array
//to make the process?
delete [] array;
你只需要堆栈上的数组,而不是堆上的数组。数组的大小应该在编译时知道。
const size_t N = 10;
int array[N];
// fill array
split(array);
相关文章:
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 将重载的成员函数传递给函数模板
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 具有常量引用参数的函数模板专用化
- 在指向函数中读取变量时出现分割错误
- 函数如何读取指针?
- std::span<const T> 作为函数模板中的参数
- 如何编写一个完美的缩写函数模板?
- 仅在函数模板中为那些定义了函数的类型执行函数
- 如何在C++中伪造虚拟可变参数函数模板?
- 以下代码中的函数模板有什么问题?
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- 将显式实例化的函数模板与转换匹配
- 使用定义函数模板别名
- 函数模板返回类型
- C++模板以从成员变量或成员函数中读取值
- 创建一个模板函数来读取 hdf5 中的任意数据类型
- 模板函数在读取时返回错误的值
- 在 main 中读取函数模板