Templates in C++

closed account (S3TkoG1T)
Hello,

I'm currently learning templates -- & my logic is in a knot with what I am trying to do which is the following:
-Create a function name load
-Accepts a filename (the filename is a text file of integers)
-Open the file
-Create an array(dynamically allocating an array) filling it with the elements read in from the file & returns the array(so that the return type of the array is a pointer to the element type of the array).

So here's what I have, and maybe you can help me see what I'm doing wrong.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Header file:
#ifndef BUBBLE_SORT_H
#define BUBBLE_SORT_H

#include <iostream>

template <typename T>
void load(std::string filename, T *&arr, int *size);

template <typename T>
void load(std::string filename, T *&arr, int *size) {
	T n;
	arr = load<int>("myfile.txt", size);
	for(int i = 0; i < n; i++)	
}

#endif  



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Main .cpp
#include <iostream>
#include <string>

#include "bubble_sort.h"

using namespace std;


int main() {
	
	int size;
	int *arr = new int[size];
	
		
	load<int>("integer.txt",arr, size); // Help!
	
	delete [] arr;	
return 0;
}


Any input would be greatly appreciated! My main problem is understanding how to allocate memory when it comes to using templates..
http://ideone.com/o4g6Oc

I use an std::istream instead of a std::string but it should demonstrate the idea.
closed account (S3TkoG1T)
you saved me from the abyss : ) Thank you kindly.
Topic archived. No new replies allowed.