作者:Candy王丫丫 | 来源:互联网 | 2023-10-13 11:43
Igotthiscode(IknowitsinSpanishIcantranslateifneeded)wheretheygivemethefunctionS
I got this code (I know it's in Spanish I can translate if needed) where they give me the function SumVec. What the function does is it receives as parameters two arrays (integer pointers) and an integer (size) and returns a pointer to the sum of the two vectors or arrays. I have to convert it so it can receive any type, not just integer. I know that you do that with a template by using "template " but I've only done simple classes I don't know how to do it with pointers. Any help?
我得到了这个代码(我知道它是西班牙文,我可以翻译,如果需要),他们给我的功能SumVec。该函数的作用是作为参数接收两个数组(整数指针)和一个整数(大小),并返回指向两个向量或数组之和的指针。我必须转换它,以便它可以接收任何类型,而不仅仅是整数。我知道你通过使用“模板”使用模板来做到这一点,但我只做了简单的类,我不知道如何用指针来做。有帮助吗?
The code
#include
#include
using namespace std;
int * sumVec(int*, int*, int);
int main() {
int n, nCol, nFil = 0;
//Arreglo unidimensional dinmico
int *ptr, *suma, size;
cout <<"Cuantos Items va a procesar:";
cin >> size;
ptr = new int[size];//Asignando memoria al arreglo
//input
for (int i = 0;i> ptr[i];
}
//Mostrando el contenido del archivo
for (int i = 0;i
1 个解决方案