Use of iterator across files and classes

Nov 18, 2013 at 5:07pm
Dear all,
here's a few parts of a program I'm working at. It does compile, and it does work as expected. Anyway Eclipse Kepler marks one line as a bug with the remark Field 'befehl' could not be resolved.
The bug sign didn't show up when both classes were in one file.

ScriptInterpreter maintains and processes a vector of Objects, initialised with example data. An iterator of the vector keeps track of the current position while various methods process the data. I've copied the relevant lines only.

I can live with a few wrongly bug-marked lines in Eclipse. What I don't want is any hidden errors that express at some time later.

Is there anything wrong with the code? Anything that's not recommended and compiles anyway? Is anything c++11-specific about the questionable line?

AtomicCommand.h
1
2
3
4
class AtomicCommand {
public:
 	int befehl;
}

ScriptInterpreter.h
1
2
3
4
5
6
7
8
9
#include <vector>
#include "AtomicCommand.h"
class ScriptInterpreter {
protected:
	vector<AtomicCommand> script;
	vector<AtomicCommand>::iterator command_it;
	bool zeile();
	ScriptInterpreter();
}


ScriptInterpreter.cpp
1
2
3
4
5
6
7
8
9
10
11
#include "ScriptInterpreter.h"
bool ScriptInterpreter::zeile() {
	if (command_it->befehl == 0) { //Line with a bug sign
		return true;
	}
}

ScriptInterpreter::ScriptInterpreter() {
	script.emplace_back(0, 0, 0, nullptr, 0);
	command_it = script.begin();
}


Note that line 9 has a bug sign, too. Eclipse doesn't recognise all my c++11 code.
Nov 18, 2013 at 5:12pm
Ignore IDE/Intellisense "bug signs". The only thing that matters is whether or not you get a compiler warning/error when you build.

Do you? If so, post the error message. If not, don't worry about it (and/or turn off that feature in your IDE, since it's apparently flakey and unreliable).


EDIT: to clarify....

IDE 'bug signs' are there to help you spot compiler errors before you actually compile. They do not spot logic errors.

So I can't say whether or not the code you wrote will work as you expect (neither can your IDE).
Last edited on Nov 18, 2013 at 5:13pm
Nov 18, 2013 at 5:48pm
Thank you for the reassurance, Disch.
The compiler does not complain about anything I'm doing in that part of the code. The excerpts are taken from working code that does exactly what it's meant to do.

If nobody contradicts, I'll stick to your advice and trust the compiler rather than the IDE.
Nov 18, 2013 at 6:30pm
Intellisense is something difficult for IDEs to get right, and often it can get confused very easily and seemingly for no reason. If the IDE's intellisense can't figure out how to understand your code, but the compiler can, just turn it off for that specific project.
Nov 18, 2013 at 6:39pm
Thank you, L B.
Topic archived. No new replies allowed.