Is this a case of cyclic include. Doesn't look so to me. Still getting error: expected class-name before ‘{’ token
Mar 16, 2017 at 9:06pm UTC
Hi guys :),
I am getting this error: expected class-name before ‘{’ token, while trying to compile my code.
I went through the net to find out the cause and found that cyclic include might be a cause.
But on verifying my code, I don't feel it's a case of cyclic include.
I had two clarifications :/
1) Is this an issue of cyclic include ? If yes, how ?
2) If not cyclic include issue, what's the problem with this code (I can't find any :/ )
Here's the error :
In file included from approval_manager.h:5:0,
from approval_manager.cpp:1:
approval_handler_tm.h:7:1: error: expected class-name before ‘{’ token
{
^
approval_handler_tm.h:14:35: error: ‘ApprovalHandler’ has not been declared
virtual void setSuccessor(ApprovalHandler *p_successor);
approval_manager.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#ifndef APPROVAL_MANAGER_H_
#define APPROVAL_HANDLER_H_
#include "approval_handler.h"
#include "approval_handler_tm.h"
class ApprovalManager
{
private :
void initialize();
ApprovalHandlerTM* approvalHandlerTM;
public :
ApprovalManagr();
~ApprovalManager();
bool approve(unsigned int amount) const ;
};
#endif
approval_manager.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "approval_manager.h"
ApprovalManager::~ApprovalManager() {}
ApprovalManager::ApprovalManager()
{
approvalHandlerTM = new ApprovalHandlerTM();
approvalHandlerTM->setSuccessor(nullptr );
}
bool ApprovalManager::approve(unsigned int amount) const
{
return approvalManagerTM->approveRequest(amount);
}
approval_handler.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#ifndef APPROVAL_HANDLER_H_
#define APPROVAL_HANDLER_H_
class ApprovalHandler
{
protected :
ApprovalHandler *successor;
public :
virtual void setSuccessor(ApprovalHandler* p_successor) = 0;
virtual bool approveRequest(unsigned int amount) const = 0;
};
#endif
approval_handler_tm.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#ifndef APPROVAL_HANDLER_TM_H_
#define APPROVAL_HANDLER_TM_H_
#include "approval_handler.h"
class ApprovalHandlerTM : public ApprovalHandler
{
private :
const unsigned int TM_APPROVAL_LIMIT = 1000;
public :
ApprovalHandlerTM();
virtual ~ApprovalHandlerTM();
virtual void setSuccessor(ApprovalHandler* p_successor);
virtual bool approveRequest(unsigned int amount) const ;
};
#endif
approval_handler_tm.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include "approval_handler_tm.h"
ApprovalHandlerTM::ApprovalHandlerTM() {}
ApprovalHandlerTM::~ApprovalHandlerTM() {}
void ApprovalHandlerTM::setSuccessor(ApprovalHandler* p_successor)
{
successor = p_successor;
}
bool ApprovalHandlerTM::approveRequest(unsigned int amount) const
{
if (amount <= TM_APPROVAL_LIMIT)
return true ;
if (successor == nullptr )
return false ;
return successor->approveRequest(amount);
}
Thanks :)
Last edited on Mar 16, 2017 at 9:08pm UTC
Mar 16, 2017 at 10:55pm UTC
The problem is that the include guard for approval_manager.h defines APPROVAL_HANDLER _H_ when it should be defining APPROVAL_MANAGER _H_ .
Mar 17, 2017 at 4:46pm UTC
thanks @Peter87 for pointing that out :)
silly mistake :(
Topic archived. No new replies allowed.