The error message means that your int energySystem::getEnergyLevel() should be made a const member function in order to be called with a const energySystem object. That is, you need the following prototype:

int energySystem::getEnergyLevel() const; //notice 'const' here.

Any "getter"-style functions should be declared as "const" functions.
i.e.:

int energySystem::getEnergyLevel() const;

Notice the "const" in the declaration...

The "this" is an "invisible" pointer that all non-static member functions have. It is a pointer to the object that called the function.

For example, if you have the call a.getEnergyLevel() in your code, "this" would be a pointer to the object that was used to call the function (the object of type energySystem identified as 'a'). It is used inside the definition/implementation of member functions to explicitly resolve the scope of identifiers that are members of the same class, such as other functions or member variables. Your energySystem::getEnergyLevel() function could be re-written as:

int energySystem::getEnergyLevel() const {
  return this->energyLevel;
}

EDIT:
Oops, Mike beat me to it...

Yay, I finally got it to work :)

Thank you for all the help, especially FBody.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.