Conception problem! Class and functions organization!!

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Conception problem! Class and functions organization!!

Post by GianT » Wed Jun 22, 2005 12:48 am

Hi, I have in my program 2classes, the main one (for the frame, the dialogs etc) and the class ThreadServer (which contains the Entry function for the thread). Here is my problem: my main frame has to include the heades of class ThreadServer, but in the thread I have to manipulate objects from the main class!! And obviously, I can't include the main class in the threadserver one... How can I acces objects, variables and functions of the main class from the class ThreadServer?? :cry:

Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank » Wed Jun 22, 2005 1:40 am

Use Forward-Declarations. Like this

Code: Select all


Header 1:

class A;

class B {
   A* m_myA;
   // etc...
};

Header 2:

class B;

class A {
   B* m_myB;
   // etc...
};

This way, the compiler knows anything he needs to know.

GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT » Wed Jun 22, 2005 1:49 am

I guess people will be fed up with me finding the solutions to the problems I post, :oops: but I just ask a friend on msn about this and he told me to use #ifndef in the header file of the thread class:

Code: Select all

#include "newProgramFrame.h" // Main class

#ifndef thread
#define thread

...
 // Class, Function declarations ....
...

#endif
With this, I can access to the functions of the main class from the thread class and there is no compilation error.
Thanks for your answer

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Wed Jun 22, 2005 6:05 am

IF you use IFNDEF use some more unique names. It is preferred that the filename is used, plus some extension. Like

Code: Select all

#ifndef WX__TREEMULTICTRL__H
#define WX__TREEMULTICTRL__H

.. your code here

#endif
If you define common words you will probably have the situation where those are already defined, and gives you strange compiler errors ;-)

The best way to define an unique header is a GUID dump. It is a 16 bytes globally unique identifyer, so there is nearly nill chance that someone in the world will make the same header ID as you ;-)

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply