Undeclared Identifier, but it is declared!!

Stash (3)
I have a program with a class in different files, I've included the header file but it still keeps saying 'undeclared identifier'


class header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef SEARCHING_H
#define SEARCHING_H

#include "Assignments.cpp"

class searching {
	public:
		searching();
		int menu();
		int searchClass(task tasks[], int num, int searchedTasks[]);   //Searches by Class
		int searchAssign(task tasks[], int num, int searchedTasks[]);  //Searches by Assignment
		void displaySearch(task tasks[], int searchedTasks, int num);
	private:
		int choice;
		int count;
		char searchName[100];
};


#endif 


Main File:
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
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

#include "searching.h"

...........
...........
...........


//Processes the users command and decides what to do with it
void processCommand(const int com, task tasks[], int& num) {
	int taskNum;
	int searchCom;
	int searchedTasks[100] = {0};
	int searchCount;
	switch(com) {
	case 1:
		listTasks(tasks, num);
		break;
	case 2:
		inputTask(tasks, num);
		break;
	case 3:
		if(num > 0) {
			cout << "What is the number of the task you want to delete?: ";
			cin >> taskNum;
			if((taskNum <= num) && (taskNum > 0)) {
				deleteTask(tasks, taskNum, num);
			}else {
				cout << "Number " << taskNum << " not valid.\n";
			}
		}else {
			cout << "There are no tasks to delete!!\n";
		}
		break;
	case 4:
		searching search;
		searchCom = search.menu();
		switch(searchCom) {
			case 1:
				searchCount = search.searchClass(tasks, num, searchedTasks);
				break;
			case 2:
				searchCount = search.searchAssign(tasks, num, searchedTasks);
				break;
		}
		if(searchCount == 0) {
			cout << "No results to display!\n";
			pause();
		}else {
			search.displaySearch(tasks, searchedTasks, searchCount);
			pause();
		}

	case 5:
		cout << "Bye Bye!\n";
		break;
	}
}


The problem happens at case 4 when I try to declare the object searching search;

I've tried to find the answer elsewhere but nothing I found worked.
kempofighter (1139)
Declaring new variables within a case is not possible without enclosing the case within brackets.

Try
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
case 4:
{
		searching search;
		searchCom = search.menu();
		switch(searchCom) {
			case 1:
				searchCount = search.searchClass(tasks, num, searchedTasks);
				break;
			case 2:
				searchCount = search.searchAssign(tasks, num, searchedTasks);
				break;
		}
		if(searchCount == 0) {
			cout << "No results to display!\n";
			pause();
		}else {
			search.displaySearch(tasks, searchedTasks, searchCount);
			pause();
		}
}
Stash (3)
Ok.... I tried that but it still says 'Undeclared Identifier!' I even tried putting the object declaration outside of the switch statement, but the error is still there.
kempofighter (1139)
That's goofy. I do believe that the brackets are necessary when declaring variables within a case so you'll need that eventually. I'm always skeptical when someone does a partial copy and paste as you have done. It makes me wonder if I am really looking at exactly what you are trying to compile. Is there a typo in the file name for the header class? Is the compiler really finding the header file at all? I would start looking for silly mistakes like that.

By the way, what OS are you using? Linux or Windows? Does the following thread help you at all?
http://www.cplusplus.com/forum/unices/13364/
Lodger (73)
1
2
3
4
5
6
7
8
9
#ifndef SEARCHING_H
#define SEARCHING_H

// Don't do this!
#include "Assignments.cpp"

class searching {
	public:
...


Don't include cpp files. Add them to your project, compile and link them.
kempofighter (1139)
Good catch. I didn't even notice that.
Registered users can post here. Sign in or register to post.