class A
{
public:
static bool S(int);
static string str;
static int integer;
};
bool A::S(int)
{
str+="A";
}
When I build the program, an error occurs: "str" undeclared identifier.
class A
{
public:
static bool S(int);
static string str;
static int integer;
};
bool A::S(int)
{
str+="A";
}
When I build the program, an error occurs: "str" undeclared identifier.
Ignoring for a second that the type is undefined, you will still get this error even if you use int
s only.
The error you are seeing is because you are missing the definition of your static variable. You have declared it only.
string A::str = "initial value";
See: What is the difference between a definition and a declaration?
Probably you have more than one error, and the one you are centering your attention on is the least important:
string
does not name a type str
undeclared.The str
is undefined because the type used to define it does not exist.
The solution would be to add
#include <string>
using namespace std;
at the beginning of the file (not that I recomment the using
line anyway, but that's another story).
You should always center your attention into the very first error the compiler issues. But some popular IDEs out there are noteworthy for reordering them.