我想编写泛型函数(例如,获取'void**'类型的数组并对此数组做一些事情的函数),这样这个函数将得到元素的类型(在示例中,它将是类型数组中的任何元素)作为参数.
我可以用c做吗?
例如:
我想编写一个获取数组(类型为void**)的函数,并以某种随机方式初始化此数组.
什么是"以某种随机方式"的含义 - 例如作为参数获取的函数:array(在类型void**中),数组中任何元素的类型,index(在int的类型中)并初始化此单元格.
有人可以解释该错误的含义:
从'std :: vector <int,std :: allocator <int>> :: const_iterator {aka __gnu_cxx :: __ normal_iterator <const int *,std :: vector <int,std :: allocator <int> >>}'转换到非标量类型'std :: vector <int,std :: allocator <int>> :: iterator {aka __gnu_cxx :: __ normal_iterator <int *,std :: vector <int,std :: allocator <int>>> }'请求
给定以下类别:
#include <vector>
#include <iostream>
using std::vector;
using std::ostream;
template<class T>
class Gen {
vector<T> array;
public:
explicit Gen(int size);
template<class S>
friend ostream& operator<<(ostream& os, const Gen<S>& g);
};
template<class T>
Gen<T>::Gen(int …Run Code Online (Sandbox Code Playgroud)