Class object not defined although instantiated by NEW

I am having a problem of un-instantiated object in my code, although i have instantiated it in my switch control structure.

Also, the commented line at end of main delete Google , produces a segmentation fault i dont know why.

Please help me out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
int main()
{
	
//	string filename=ReadLine("Please enter the name of the file : ");
	ifstream fin;
//	fin.open(filename.c_str());
	fin.open("data.txt");

	    struct timeval start, end, diff;

	if (fin.fail())
	{
		cout<<"Unable to open the specified file name "<<endl;
		return 0;
	}
	else
	{
		string selectengine=ReadLine("Please Enter the representation to use: 1.List, 2.BST, 3.AVL \n >");
		int select=atoi(selectengine.c_str());
		switch (select)
		{
			case 1:
			{
				ListEngine* Google=new ListEngine();
				break;
			}
			case 2:
			{
				BST* Google=new BST();
				break;
			}
			case 3:
			{
//				AVL* Google=new AVL();
				break;
			}
			default:
			{
				cout<< "Invalid option, choosing List as SearchEngine ."<<endl;
				ListEngine* Google=new ListEngine();
				break;
			}
		}
//		BST* Google=new BST();
		
		gettimeofday(&start, NULL);

		Google->LoadData(fin);

		gettimeofday(&end, NULL);
		timeval_subtract(&diff, &end, &start);
		cout << "File Loaded Successfully in " << diff.tv_sec << " seconds and " << diff.tv_usec << " microseconds." << endl;
		fin.close();
		
		int choice=0;
		
		while (choice!=2)
		{
			string c=ReadLine(" Please choose : 1.Search 2.Exit 3.Delete a word \n >");
			choice=atoi(c.c_str());			
			switch (choice)
			{	
				case 1:
				{	
					string word=ReadLine("Please enter a word to search : \n > ");
					gettimeofday(&start, NULL);
					Google->SearchResults(word);
					gettimeofday(&end, NULL);
					timeval_subtract(&diff, &end, &start);
				 	cout << "Search took " << diff.tv_sec << " seconds and " << diff.tv_usec << " microseconds." << endl;
					break;
				}
				case 2:
				{
					break;
				}
				case 3:
				{
					string word=ReadLine("Please enter the word to delete: \n > ");
				//	Google->DeleteWord(word);
					break;
				}
				default:
				{
					cout<< "Invalid Choice "<<endl;
				}
			}
		}
//		delete Google;
	}
}


Compiling above code gives the following error


Task1.cpp: In function âint main()â:
Task1.cpp:70: error: âGoogleâ was not declared in this scope
The Google variable is declared in the switch construct so it is not available outside, you need to declare it before
but how do i know what type will be Google beforehand ?
Is the Google variable type a type of your own? If yes use an abstract base class which BST, AVL... will implement.
If no, well... you will have to declare a variable for each type but it will be a mess...
yea I have a ListEngine class BST class and AVL class which i am using to search urls,

I think going in to the mess will be a better idea for me as i am not really comfortable with derived classes
As you want but you have all you need in this site:
http://www.cplusplus.com/doc/tutorial/polymorphism/
thanks
Topic archived. No new replies allowed.