Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 转换标准::向量<;常数类型*>;to const std::vector<;T、 A>&;Vec_C++_Std - Fatal编程技术网

C++ 转换标准::向量<;常数类型*>;to const std::vector<;T、 A>&;Vec

C++ 转换标准::向量<;常数类型*>;to const std::vector<;T、 A>&;Vec,c++,std,C++,Std,我继承了一些代码,并坚持我认为应该是一个简单的更新 我有以下功能 template<typename T> class ArrayRef { public: typedef const T *iterator; typedef const T *const_iterator; private: /// The start of the array, in an external buffer. const T *Data; public: /// Construct an Ar

我继承了一些代码,并坚持我认为应该是一个简单的更新

我有以下功能

template<typename T>
class ArrayRef { 
public:
typedef const T *iterator;
typedef const T *const_iterator;

private:
/// The start of the array, in an external buffer.
const T *Data;

public:
/// Construct an ArrayRef from a std::vector.
template<typename A>
ArrayRef(const std::vector<T, A> &Vec)
: Data(Vec.empty() ? (T*)0 : &Vec[0]), Length(Vec.size()) {}
};
模板
类ArrayRef{
公众:
typedef const T*迭代器;
typedef常量T*常量迭代器;
私人:
///数组的开头,在外部缓冲区中。
常数*数据;
公众:
///从std::vector构造ArrayRef。
模板
ArrayRef(常量标准::向量和向量)
:数据(Vec.empty()?(T*)0:&Vec[0]),长度(Vec.size()){}
};
我需要传递一个向量,定义如下,给这个函数

std::vector<const myType*> myVector(4);
std::vector myVector(4);
最简单的方法是什么?

只需传递向量:

ArrayRef<const myType*> myArrayRef(myVector);
ArrayRef myArrayRef(myVector);

是否有某些原因导致此操作不适用于您?

是否为函数的
t
A
模板参数?如果是那样的话,它应该就行了。如果不是,它们是什么类型,以及
t
myType
的关系如何?我把整个函数定义都放进去了,这能让它更清楚吗?你的代码中
t
是什么?@SamCoulter:你仍然没有显示你正在使用的
ArrayRef
类模板的实例:换句话说,实例化
ArrayRef
时,您为
T
提供的类型参数是什么?是
ArrayRef
?这是正确的,在其他地方有一个编译错误阻止了它的工作(并发出一条指向此行的错误消息)。现在修好了。谢谢你的回答。