I have a function called:
void initializeJSP(string Experiment)
And in my MyJSP.h file I have:
2: void initializeJSP(string Experiment);
And when I compile I get this error:
MyJSP.h:2 error: variable or field initializeJSP declared void
Where is the problem?
It for example happens in this case here:
Try using
std::string
instead of juststring
(and include the<string>
header). C++ Standard library classes are within the namespacestd::
.Other answers have given very accurate responses and I am not completely sure what exactly was your problem(if it was just due to unknown type in your program then you would have gotten many more clear cut errors along with the one you mentioned) but to add on further information this error is also raised if we add the function type as void while calling the function as you can see further below:
Error:
So as we can see from this example this reason can also result in "variable or field declared void" error.
This is not actually a problem with the function being "void", but a problem with the function parameters. I think it's just g++ giving an unhelpful error message.
The thing is that, when you call a function you should not write the type of the function, that means you should call the funnction just like