Click here to Skip to main content
15,897,226 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ON_MESSAGE for CDialog OBJECT Pin
ForNow25-Feb-09 16:46
ForNow25-Feb-09 16:46 
QuestionMemory Allocation Error 998 Pin
Richard Andrew x6425-Feb-09 14:06
professionalRichard Andrew x6425-Feb-09 14:06 
AnswerRe: Memory Allocation Error 998 Pin
Stuart Dootson25-Feb-09 16:03
professionalStuart Dootson25-Feb-09 16:03 
GeneralRe: Memory Allocation Error 998 Pin
Richard Andrew x6425-Feb-09 16:08
professionalRichard Andrew x6425-Feb-09 16:08 
AnswerRe: Memory Allocation Error 998 Pin
ky_rerun25-Feb-09 16:25
ky_rerun25-Feb-09 16:25 
GeneralRe: Memory Allocation Error 998 Pin
Richard Andrew x6425-Feb-09 16:30
professionalRichard Andrew x6425-Feb-09 16:30 
AnswerRe: Memory Allocation Error 998 Pin
User 268325825-Feb-09 19:39
User 268325825-Feb-09 19:39 
QuestionForward Declarations, Inheritance and Circular dependancies Pin
thelonesquirrely25-Feb-09 10:19
thelonesquirrely25-Feb-09 10:19 
Hello,

I am having a problem with setting up a necessary circular dependency.

I have a class (MessageHandler) which inherits from a "interface" as much as you're allowed to do that in c++. It also contains a queue (TaskQueue). and here is the circular bit: the TaskQueue needs a reference to the MessageHandler. The other catch is that the Tasks in TaskQueue need to know about the MessageHandler.

So the code goes like this (or at least the screwy parts):

(in MessageHandler.h)
#ifndef MESSAGE_HANDLER_H
#define MESSAGE_HANDLER_H

#include "TaskQueue.h"

class MessageHandler : public somenamespace:someclass {
private:
  TaskQueue tq;
  someobj& ref;
  ... //not using tq
public:
  MessageHandler (someobj& r) : ref (r) {
    tq.setMessageHandler (&this);
    ..//some other no relevant stuff
  }
};
#endif

(MessageHandler.C)
#include "MessageHandler.C"
..some functions making use of tq..

(in TaskQueue.h)
#ifndef TASK_QUEUE_H
#define TASK_QUEUE_H

#include "Tasks.h"

class MessageHandler; //forward declaration

class TaskQueue : public someotherclass {
private:
  MessageHandler* msg_handler;
  ..other queue-things...

public:
  TaskQueue () {...}
  inline void setMessageHandler (const MessageHandler* mh) { msg_handler = mh; }

  void doSomething () {
    msg_handler->doSomething ();
  }
};
#endif

(in Tasks.h)
#ifndef TASK_H
#define TASK_H

class MessageHandler;

class Task {
private:
  MessageHandler* msg_h;

public:
  Task (const MessageHandler* mh) {msg_h = mh;}
}

(int Tasks.C)
#include "Tasks.h"

void Task::someFunction () {
  msg_h->someFunction ();
}
#endif


I am not sure if the forward declaration is right; do I need to include the ": public..." inheritance stuff?

Main is somewhere else, and it just does has:

#include "MessageHandler.h"
...
MessageHandler msg_handler;
...
that part is pretty standard.

The first couple of errors I get from the compiler (gcc) is:
./include/MessageHandler.h:18: error: declaration of âstruct TaskQueue::MessageHandlerâ
./include/Tasks.h:21: error: changes meaning of âMessageHandlerâ from âstruct MessageHandlerâ
./include/MessageHandler.h:21: error: field âtask_qâ has incomplete type
./include/MessageHandler.h:24: error: expected â,â or â...â before â:â token
....all hell breaks loose

Any help is appreciated!
AnswerRe: Forward Declarations, Inheritance and Circular dependancies Pin
Jonathan Davies25-Feb-09 10:41
Jonathan Davies25-Feb-09 10:41 
GeneralRe: Forward Declarations, Inheritance and Circular dependancies Pin
thelonesquirrely25-Feb-09 10:54
thelonesquirrely25-Feb-09 10:54 
AnswerRe: Forward Declarations, Inheritance and Circular dependancies Pin
led mike25-Feb-09 11:55
led mike25-Feb-09 11:55 
AnswerRe: Forward Declarations, Inheritance and Circular dependancies Pin
Stuart Dootson25-Feb-09 11:59
professionalStuart Dootson25-Feb-09 11:59 
GeneralRe: Forward Declarations, Inheritance and Circular dependancies Pin
thelonesquirrely25-Feb-09 13:02
thelonesquirrely25-Feb-09 13:02 
QuestionError creating an object based on a dialog declared in a .rc resource file Pin
Goo225-Feb-09 9:49
Goo225-Feb-09 9:49 
AnswerRe: Error creating an object based on a dialog declared in a .rc resource file Pin
Jonathan Davies25-Feb-09 10:10
Jonathan Davies25-Feb-09 10:10 
GeneralRe: Error creating an object based on a dialog declared in a .rc resource file Pin
Goo225-Feb-09 11:49
Goo225-Feb-09 11:49 
GeneralRe: Error creating an object based on a dialog declared in a .rc resource file Pin
Goo225-Feb-09 12:45
Goo225-Feb-09 12:45 
GeneralRe: Error creating an object based on a dialog declared in a .rc resource file Pin
Jonathan Davies25-Feb-09 14:16
Jonathan Davies25-Feb-09 14:16 
QuestionHow can I access CView within CDoc in a SDI? Pin
Joseph Marzbani25-Feb-09 9:41
Joseph Marzbani25-Feb-09 9:41 
AnswerRe: How can I access CView within CDoc in a SDI? Pin
Jonathan Davies25-Feb-09 10:30
Jonathan Davies25-Feb-09 10:30 
AnswerRe: How can I access CView within CDoc in a SDI? Pin
«_Superman_»25-Feb-09 17:41
professional«_Superman_»25-Feb-09 17:41 
AnswerRe: How can I access CView within CDoc in a SDI? Pin
Hamid_RT25-Feb-09 19:43
Hamid_RT25-Feb-09 19:43 
AnswerRe: How can I access CView within CDoc in a SDI? Pin
Iain Clarke, Warrior Programmer26-Feb-09 1:54
Iain Clarke, Warrior Programmer26-Feb-09 1:54 
QuestionHow to resolve LNK2001 error (ver: VC ++ 8.0 and .net 2005) Pin
SIJUTHOMASP25-Feb-09 9:14
professionalSIJUTHOMASP25-Feb-09 9:14 
AnswerRe: How to resolve LNK2001 error (ver: VC ++ 8.0 and .net 2005) Pin
ky_rerun25-Feb-09 16:21
ky_rerun25-Feb-09 16:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.