Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable or field declared void

Tags:

c++

string

void

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?

like image 899
Eduardo Avatar asked Dec 12 '08 21:12

Eduardo


2 Answers

It for example happens in this case here:

void initializeJSP(unknownType Experiment);

Try using std::string instead of just string (and include the <string> header). C++ Standard library classes are within the namespace std::.

like image 145
Johannes Schaub - litb Avatar answered Oct 13 '22 13:10

Johannes Schaub - litb


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.

EDIT: As in the accepted answer, the fix is to use std::string instead of just string.

like image 34
Paul Price Avatar answered Oct 13 '22 11:10

Paul Price