Can you pass ints OR strings to the same class without it being templated?

I have a program I'm writing that reads from a file and separates the data it receives in a particular way. It is supposed to work the same way whether I give it a file of numbers or a file of strings. Right now I have it written as two separate files (I have a header and cpp for both ints and strings), but I really need it to work with just one set of files.

The problem is, I had a TERRIBLE time trying to template my class to work with both because Ive never done it before...is there any other way to try and do this? Or is templating a class the only way to get it to work with both?
maybe overloaded functions

http://www.cplusplus.com/doc/tutorial/functions2/

templates are probably preferred, umm could you display you code for both versions of the class and maybe we can help you template the class...

Last edited on
I've been using some overloaded functions and hopefully on the right track, but I cant seem to find the problem in this code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ifstream fin;
	fin.open("C:/Users/Josh/Desktop/TriNode/NumList.txt");

	int first;
	fin >> first;

	cout << first;

	if(first < 10)
	{
		trinode root(first);
		list<int>::iterator currentIt;

		while(!fin.eof())
		{
			int temp;
			fin >> temp;
			root.insert_node(temp);
		}
	}


when I try to use the trinode "root" or the iterator "currentIt" after this if statement, it keeps giving me errors saying they are not declared, which I would assume means it never gets past the IF(first <10) but If i cout << first right before, its 8.....which is obviously less than 10.
alright that was a stupid mistake...nevermind
Topic archived. No new replies allowed.