I am a new member of cplusplus forum and this is my first post here.
Currently I have a frustrating problem with forward declaration and template function. Below is the snippet of the code:
class TaskScheduler; --> //forward declaration of ‘struct TaskScheduler’
//
//
//class TaskScheduler definition
class TaskScheduler : virtual public HCIEventsHandler {
friend HostTask* findT<TaskEvent>(TaskScheduler* tss, TaskEvent* e); //findT function is used here
//
//
};
Here is the error message that I've got which is shown in the code as well:
./bt-taskscheduler.h:159: error: forward declaration of ‘struct TaskScheduler’
./bt-taskscheduler.h:229: error: invalid use of incomplete type ‘struct TaskScheduler’
Could anybody show me what is going wrong in this code? Any help is appreciated..
Thank you all for your reply :)
@Bazzy: did you mean to move the findT after the complete TaskScheduler class? If it's so I got another error which says: ‘findT’ is neither function nor member function; cannot be declared friend.
@kbw: could you please explain me what you mean about "templated version that is specific to your familt of types or going for a more traditional OO hierarchy"?
Thank you..
As Bazzy suggested, it's the order of declaration that matters. I've filled in some minimal code to make it compile.
Looking further at what you have now, I think you need a static way to determine what kind of T is passed to findT. Taken from Alexandrescu's Loki, IsSameType will do it for you. I've added a findK to demonstrate. At least, this way you won't have the RTTI runtime overhead.
I still think the overall design needs to be revised.