I'm trying to write a program to build a BST from a file, using a template because there's more than one file type.
My first question is: How do I forward declare a pointer to a template class before I know what type it has to be? I've tried using a function (DetermineType returns an int that IDs the data type) and then declaring a pointer and pointing it to new memory of the type yielded by the function, but I think the pointer is going out of scope (?) or something?
Code:cout << "Enter the name of the file you wish to open, including extension." << endl << "(C:\\, etc) "; cin.getline(File, 50, '\n'); ifstream fin; fin.open(File); if(!fin) { cout << "Error opening file. Make sure the file exists and is not in use. "; break; } string entry; fin >> entry; fin.close(); int TreeType = DetermineType(entry); if (TreeType == 1)//int { BinarySearchTree<int> * x; x = new BinarySearchTree<int>(NULL); } else if (TreeType == 2)//char { BinarySearchTree<char> * x; x = new BinarySearchTree<char>(NULL); } else if (TreeType == 3)//double { BinarySearchTree<double> * x; x = new BinarySearchTree<double>(NULL); } else if (TreeType == 4)//string { BinarySearchTree<string> * x; x = new BinarySearchTree<string>(NULL); }
A similar problem occurs when I try to read in data from a file...I get error C2065 on the line with "fin >> fileEntry;", then the same error again on the line with "x -> insert(fileEntry);"
Code://while there is more of the file to read, //read in entries and add them to the BST while(!EOF) { if (TreeType == 1) { int fileEntry; } else if (TreeType == 2) { char fileEntry; } else if (TreeType == 3) { double fileEntry; } else if (TreeType == 4) { string fileEntry; } fin >> fileEntry;//C2065 fileEntry undeclared x -> insert(fileEntry);//C2065 x undeclared }
can anyone help?
I'm using Visual Studio .NET 7.1.



LinkBack URL
About LinkBacks



