Here's the header file code:
#ifndef __MANAGER_H__PROJECT_A__
#define __MANAGER_H__PROJECT_A__
#include <string>
class Manager {
private:
std::string type;
bool isStarted;
protected:
void setType(std::string type);
public:
Manager();
virtual ~Manager();
//Get type identifier
std::string getType();
//Startup manager. 0: Startup ok. Any #: Not ok.
virtual int startUp();
//Shutdown manager.
virtual void shutDown();
//True: startUp executed ok. False, otherwise.
bool isStarted() const;
};
#endif
The code below shows the error as "A pointer to a bound function may only be used to call the function".
bool Manager::isStarted() const {
return this->isStarted; //<---- ERROR.
}
And should be changed to this.
bool Manager::isStarted() const {
return Manager::isStarted; //<---- Correct.
}
So why is this acceptable?
void Manager::setType(std::string type){
this->type = type; //<---- Correct.
}
Thanks in advance.
Specifically, you've aliased isStarted
to be the name of a method in the class, and thus this->isStarted
is attempting to return a pointer to the member-method Manager::isStarted
rather than some boolean value isStarted
.
So your code that doesn't work doesn't work because it's not doing what you think it's doing. And your code that does work works because it's also not doing what you think it's doing; the returned pointer can be implicitly cast as a bool
(and will always be equal to true
), so you don't get a wrong return type error.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments