GCC: function was not declared in this scope

Hello, been a while since I've done any coding, went on holidays for 4months and deferred.
Anyway I have this error and can not figure out what I'm doing wrong any help is appriciated :)


wordfinder.cpp: In function 'bool parseSize(std::string, int&, int&)':
wordfinder.cpp:120: error: 'isInteger' was not declared in this scope


wordfinder.cpp
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
bool parseSize(string line, int& row, int& col)
{
	int size_pos[3]= { 0 };
	string strRow, strCol;
	// get characters from string

	size_pos[0] = line.find('=');
	size_pos[1] = line.find(',');
	size_pos[2] = line.find_first_of(" #\t\n");

	int len1 = size_pos[1] - size_pos[0] - 1;
	strRow = line.substr(size_pos[0]+1,len1);
	int len2 = size_pos[2] - size_pos[1] - 1;
	strCol = line.substr(size_pos[1]+1,len2);

	// check characters are valid numbers
	// and puzzle size is ok
	if (isInteger(strRow,row))
	{
		if (isInteger(strCol,col))
		{
			if (row>1 && col>1)
				return true;
			cout << "Puzzle size is too small: "
				<< row << " * " << col << endl;
		}
		else
			cout << "Column is not a valid number." << endl;
	}
	else
		cout << "Row is not a valid number." << endl;
	return false;
}

//=============================================//

void wordfinder::convert2Upper(string& str)
{
	for (unsigned i=0; i<str.length(); i++)
		str[i]=toupper(str[i]);
}

//=============================================//

bool wordfinder::isInteger(string& str, int& i)
{
	istringstream ss(str);
	return ss >> i ? true : false;
}

wordfinder.h
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
#ifndef WORDFINDER_H
#define WORDFINDER_H

#include <string>
#include <iostream>
#include <cstdlib>
#include <new>
#include <fstream>
#include <sstream>


class wordfinder
{
   public:
      wordfinder();
      wordfinder(std::string);
      ~wordfinder();
      void parseFile();
      void processString(std::string& line);
      bool parseWord(std::string line,std::string& word);
      bool parseSize(std::string line,int& row,int& col);
      void convert2Upper(std::string& str);
      bool isInteger(std::string& str,int& i);
      void resetBools();
      bool isComment(std::string& str);
      bool isSize(std::string& str);
      bool isSearch(std::string& str);
   private:
      std::string filename;
      bool gotSize;
      bool gotWord;
      bool gotPuzzle;
};

#endif 
In the first code snippet, move the IsInteger() function definition to above the parseSize() function definition.
You need to qualify the function definition with the name of the class it belongs to like this:

1
2
3
4
bool wordfinder::parseSize(string line, int& row, int& col)
{
    // ...
}
edit: heh thnx Galik, I found it as well. :)

so annoying when simple mistakes take 3+ hours to find...
wasn't until I saw the small snippet I posted that I saw the problem.
Last edited on
Vexer wrote:
In the first code snippet, move the IsInteger() function definition to above the parseSize() function definition.

Thought I'd comment on this:
Function definitions are already included by the header file which is included by the pre-processor before compile time.
Where the actual function is placed in the .cpp file is irrelevant.

edit:
Unless of course your not using headers, simply functions as part of a file.
eg won't work:
1
2
3
4
5
6
7
8
9
10
int main()
{
   somestuff();
   return 0;
}

void somestuff()
{
   cout << "Hello world";
}

eg will work:
1
2
3
4
5
6
7
8
9
10
11
12
void somestuff();

int main()
{
   somestuff();
   return 0;
}

void somestuff()
{
   cout << "World Hello";
}


the second code snippet is similar to what the preprocessor does for header files.
Last edited on
1
2
3
4
5
6
7
8
9
10
void somestuff()
{
   cout << "World Hello";
}

int main()
{
   somestuff();
   return 0;
}
Will also work... though this is probably irrelevant. Also take note that I really didn't read much into this thread, and may be saying something stupid...
Last edited on
Thought I'd comment on this:
Function definitions are already included by the header file which is included by the pre-processor before compile time.
Where the actual function is placed in the .cpp file is irrelevant.


Ah...

Thanks, I knew this was true for regular functions, wasn't sure about methods.
Topic archived. No new replies allowed.