Reputation: 509
I have a function which will pop task-codes from a queue and search it in a map of task-codes and tasks(methods) and push the the matched task into another queue which I want to pop out and executed sequentially later. Below is the function:
void CertManMgmtEECertController::PrepareTask()
{
while(_taskCodeQueue.empty())
{
_taskQueue.push((_taskStore.find(_taskCodeQueue.pop()))->second);
}
}
Below is the header where the class of this function is defined:
class CertManMgmtEECertController : public virtual CertManMgmtCertificate
{
public:
CertManMgmtEECertController();
~CertManMgmtEECertController();
void PerformTask();
void SetTask(CertManMgmtEETaskCode taskCode);
typedef void (CertManMgmtEECertController::*Task)();
private:
CertManMgmtEETaskCode _task;
queue<Task> _taskQueue;
queue<CertManMgmtEETaskCode> _taskCodeQueue;
map<CertManMgmtEETaskCode,Task> _taskStore;
void LoadTasks();
void PrepareTask();
void ExecuteTaskQueue();
void GetEECert();
bool GetCertificate();
};
But I am getting this below error while compiling:
CertManMgmtDomainController.h:49: error: 'CertManMgmtEECertController' does not name a type
CertManMgmtEECertController.cpp: In member function 'void certman::CertManMgmtEECertController::PrepareTask()':
CertManMgmtEECertController.cpp:42: error: invalid use of void expression
CertManMgmtEECertController.cpp: In member function 'void certman::CertManMgmtEECertController::ExecuteTaskQueue()':
CertManMgmtEECertController.cpp:55: error: void value not ignored as it ought to be
Where am I going wrong? I know there are other compilation errors here too. Please help.
Upvotes: 0
Views: 1247
Reputation: 169
See if adding namespace
in typedef
help.
typedef void (certman::CertManMgmtEECertController::*Task)();
Upvotes: 0
Reputation: 145359
A good rule of thumb is to start with the first error message.
In your case that is
CertManMgmtDomainController.h:49: error: 'CertManMgmtEECertController' does not name a type
Possibly you have a typo, possibly the header is not included in the implementation file, possibly the identifier has been redefined as a function, whatever. But start with this. Ignore the rest of the errors: they are quite probably possibly caused by this first one.
Edit: After writing the above I see in another answer that you're using a std::queue
, and indeed, its pop
method returns void
. This is for exception safety. There is no convenience method that combines pop
and front
.
Regarding the typo possibility, note that
modern IDEs such as Visual Studio provide tooltips about identifiers, and
C++ provides namespaces to deal with common prefixes in a more practical way.
Upvotes: 0
Reputation: 41321
In principle the question contains enough information to answer about invalid use of void expression
error.
std::queue::pop() returns void
. What you want in PrepareTask
is probably
while (!_taskCodeQueue.empty()) {
// ^^^ also fixed condition
_taskQueue.push((_taskStore.find(_taskCodeQueue.front()))->second);
_taskCodeQueue.pop();
}
Upvotes: 3