You can declare pointers of forward-declared classes and pass them around.
compiler havent seen the actual class declaration yet.
"Mr. Sir Bossman" <messiah2999@yahoo.com> wrote in message
Why do you always post twice (or four times to be exact) ?
Sry, just realized microsoft site is messed and not working(using
google now).
Why don't you do what Igor or I told you in the other thread
("error C2027: use of undefined type 'A'") ?
I did what you said and it gave me:
a.h(10) : error C2065: 'g_main' : undeclared identifier
a.h(10) : error C2227: left of '->SomeDriver' must point to class/
struct/union/generic type
type is ''unknown-type''
main.h(18) : error C2040: 'g_main' : 'main *' differs in levels of
indirection from ''unknown-type''
error C2040: 'g_main' : 'main *' differs in levels of indirection from
''unknown-type''
error C2227: left of '->a' must point to class/struct/union/generic
type
type is ''unknown-type''
error C2227: left of '->a' must point to class/struct/union/generic
type
type is ''unknown-type''
error C2227: left of '->Print' must point to class/struct/union/
generic type
error C2227: left of '->a' must point to class/struct/union/generic
type
type is ''unknown-type''
error C2227: left of '->SomeFunction' must point to class/struct/union/
generic type
**********Files with changes
#include "stdafx.h"
#include <stdio.h>
#include "main.h"
#include "A.h"
main *g_main = NULL;
int _tmain(int argc, _TCHAR* argv[])
{
g_main = new main;
g_main->a = new A;
g_main->a->Print();
g_main->a->SomeFunction();
return 0;
}
**********
#ifndef MAIN_H
#define MAIN_H
#include "A.h"
class main
{
public:
void SomeDriver()
{
printf ("driver called\n");
}
void PrintA()
{
a->Print();
}
A *a;
};
extern main *g_main;
#endif
********
#ifndef A_H
#define A_H
class main;
class A
{
public:
void SomeFunction()
{
g_main->SomeDriver();
}
void Print()
{
printf ("Characters: a\n");
}
};
#endif