error C2143: syntax error : missing ';' before '<'

error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#ifndef _lexicon_h
#define _lexicon_h


class Lexicon {
  public:
	/* Constructor: Lexicon                                                 */
	/* Constructor initializes a new lexicon to represent empty word list.  */
	Lexicon();

	/* Destructor: ~Lexicon                                                 */
	/* The destructor frees any storage associated with the lexicon.        */
	~Lexicon();

	/* Member function: getWordIterator                                     */
	/* This member function returns an iterator over all words contained    */
	/* in the lexicon in alphabetical order.                                */
	Iterator<string> getWordIterator();

};

#endif 
Was this maybe what you were looking for?
std::string::iterator getWordIterator();
can I add to the header
#include <string>

using namespace std;

rather than add the std:: prefix?
In a header file, I'd refrain from using the using namespace std; simply because you may run into issue later on. If you plan on keeping this is a local code and you've already used the using namespace call, then yes, string would be fine.

Just trying to show you properly rather than poor techniques.
thank you - always better to learn correctly, I will make the change to std::

are these correct:
bool containsWordHelper(nodeT *w, string word)
bool containsWordHelper(nodeT *w, std::string word)

void add(string word);
void add(std::string word)
Minus the missing semicolons, they appear to be.

Also, if in doubt, it doesn't hurt to try putting std:: in front of it. Compile before and after and see if you get errors the second time.
closed account (zb0S216C)
Of what type is Iterator? I don't see a declaration of Iterator nor do I see a header that could potentially house the declaration.

Wazzak
Last edited on
I edited it out for the example code

#include "iterator.h" and a few other headers are under #define _lexicon_h
closed account (zb0S216C)
Then, something you omitted is the cause. Paste the Iterator implementation (without omitting anything) here. If it's a big file, use http://www.pastebin.org/

Wazzak
Last edited on
I believe they meant they omitted the header files to reduce the size of the paste. If Iterator was defined elsewhere, then you need to know how, and how it can be used.

My response was in regards as to what was shown and since they accepted the answer, I assumed it was what they were looking for.

Iterator could have been misspelled and they could have been confused on the implementation of it.

Edit: Sorry Framework, I just found this, and it's above my head. Maybe you can help a little more?
http://www.cplusplus.com/forum/beginner/73046/
Last edited on
making the change to std:: solved the linker errors but creates a new problem.

the current edit:
Iterator<string> getWordIterator(); --> std::string::iterator getWordIterator();

now the compiler finds an issue with a mismatch between the declaration in the .h file and the call

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
#include "stdafx.h" //first uncommented line http://www.pcreview.co.uk/forums/cant-use-std-lib-t3170870.html
#include <cstdlib> //added http://forums.devx.com/showthread.php?t=152439
#include <string>
#include <iostream>
#include <set>
#include <fstream> //CIFE seed
#include "genlib.h" //www.keithschwarz.com/cs106l/winter20072008/handouts/020_Writing_Without_Genlib.pdf
#include "simpio.h"
#include "set.h"
#include "lexicon.h"

using namespace std;

/* Constants */

const int MinChoice = 0;
const int MaxChoice = 11;

/* Prototypes */

void PrintRegExpMatches(string exp, Set<string> & matches);
void PrintCorrections(string seed, int editDistance,
					  Set<Lexicon::CorrectionT> & matches);
void PrintMenu();
int GetMenuChoice();
void NewLexicon(Lexicon * & lex);
void LoadWordsFromFile(Lexicon & lex);
void AddWord1(Lexicon & lex);
void ClassifyMeasurement(Lexicon & lex);
void ContainsPrefix(Lexicon & lex);
void PrintNumWords(Lexicon & lex);
void PrintWords(Lexicon & lex);
void RegExpMatch(Lexicon & lex);
void SuggestCorrections(Lexicon & lex);
void AutoSuggestCorrections(Lexicon & lex, string line);
void DoMenuChoice(Lexicon * & lex, int choice);

void PrintWords(Lexicon & lex)
{
	cout << "All activity codes in code list" << endl;
	cout << "--------------------" << endl;

	Iterator<string> it = lex.getWordIterator();
	while (it.hasNext()) {
		string line = it.next(); //CIFE seed code
		for(int i = 2; i < 16; i+=3) line.insert(i,".");
		//cout << it.next() << endl;
		cout << line << endl;
	}
}


error C2440: 'initializing' : cannot convert from 'std::_String_iterator<_Elem,_Traits,_Alloc>' to 'Iterator<ElemType>'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "stdafx.h"
#include <cstdlib> //added http://forums.devx.com/showthread.php?t=152439
#include <string>
#include <iostream>
#include <fstream>
#include <set>
#include "genlib.h" //www.keithschwarz.com/cs106l/winter20072008/handouts/020_Writing_Without_Genlib.pdf
#include "simpio.h"
#include "lexicon.h"
#include "iterator.h"
#include "set.h" //added to match lexicon.h and main.cpp file 6/8/2012 - seemed to correct most (dozens) of errors


using namespace std;

Iterator<string> Lexicon::getWordIterator()
{
	Iterator<string> *iter = new Iterator<string>();
	allWordsHelper(root, "", iter);
	return *iter;
}


C2556: 'Iterator<ElemType> Lexicon::getWordIterator(void)' : overloaded function differs only by return type from 'std::_String_iterator<_Elem,_Traits,_Alloc> Lexicon::getWordIterator(void)'

error C2371: 'Lexicon::getWordIterator' : redefinition; different basic types

I did not post the entire code, just the header and the function the compiler found the error in


I am going to revert the edit and try another path to a solution. The Iterator<string> getWordIterator(); compiled in a previous working version so i know it works. And, the edit created the template mismatch errors. I ma going to focus on the Linker errors and check the source files.
Topic archived. No new replies allowed.