Your code does this:
StartGame::StartGame(EntitySystem& ES)
: ES(ES)
Let's break this down:
":" <- means "Memberwise initialization"
"ES(" <- means "call the constructor for member 'ES'"
"(ES)" <- these are the arguments to pass to the constructor
"{ ... }" <- here is the constructor body itself.
The trouble is, your class does not have a member called "ES".
But you also have a secondary problem.
"ES(ES)"
If you had a member variable called "ES", there would be a conflict here.
There are several widely used practices that you might want to employ to avoid problems like this in future.
- Use upper-camelcase ("SomeClass") for class, struct, type definitions.
- Use prefixes for non-local variables: "m_" for members, "s_" for statics, "g_" for globals, (some people also use "u_" for unions, "um_" for union members, etc).
- Use a '_' suffix for function arguments, e.g.
void myFunction(int arg1_, int arg2_) { ...
- Use upper-case for functions and choose a convention for naming convention for "getter" and "setter" functions.
e.g.
static size_t s_counter = 0; // count of how many things we've done.
extern size_t g_nowServing; // imported from another module.
class Customer {
size_t m_ticketNo; // which ticket number I pulled
std::string m_licensePlate;
public:
Customer(size_t ticketNo_, const char* licensePlate_)
: m_ticketNo(ticketNo_)
, m_licensePlate("")
{
// somewhat artificial implementation for demonstrative purposes.
char licensePlate[8] = "\0\0\0\0\0\0\0";
for (size_t i = 0; i < sizeof(licensePlate); ++i) {
if (!isalnum(licensePlate_[i]))
throw CustomerException("invalid character in license plate");
licensePlate[i] = licensePlate_[i];
}
if (licensePlate[sizeof(licensePlate) - 1] != '\0')
throw CustomerException("invalid license plate -- too long");
m_licensePlate = licensePlate;
}
};
This makes it much easier to immediately diagnose the problem in your code:
StartGame::StartGame(EntitySystem& es_)
: m_es(es_)
{
}
This would have produced the compiler error error: class StartGame does not have any field named m_es
and bingo - you would have been able to home in on the problem immediately.