函数模板返回的指针不能用,请问这个函数哪里出了问题

template
T* dynamicAllocateMemory(const std::vector& vector)
{
int index = 0;
T* p = (T*)malloc(sizeof(T) * vector.size());
for (auto& verticePart : vector)
{
std::cout << "verticePart" << verticePart << std::endl;
*(p + index) = verticePart;
++index;
}
return p;
}

参数不能是模板名称,应该是具体的类型,应改为 const std::vector<T>& vector。另外 std::vector 里的元素是连续的,考虑使用 memcpy 来替代 for 循环:memcpy(p, &vector[0], sizeof (T) * vector.size())