Forward declarations

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Class S contains a pointer to class main
Class main contains and instance of class
I therefore include a forward reference in S of main
The catch is I want to call a method in main from s and if I do this I get an erro
use of undefined type 'Main'
So how can I call a method in main from S and if I cant whats the point in being able to store a pointer to it?
 
I therefore include a forward reference in S of main.

This should be in the .h file
The catch is I want to call a method in main from s and if I do this I get
an error

No problem.

Try this:
1) in s.cpp: #include<main.h>
2) in main.cpp: #inlcude<s.h>

Do not try this:
1) in s.h: #include<main.h>
2) in main.h: #inlcude<s.h>

Rudy

JoNinty said:
Class S contains a pointer to class main.
Class main contains and instance of class S
I therefore include a forward reference in S of main.
The catch is I want to call a method in main from s and if I do this I get an error
use of undefined type 'Main'.
So how can I call a method in main from S and if I cant whats the point in
being able to store a pointer to it?
 
You can't define the function inline. The following should work

class main

class S
main* m
void foo()
}

class main
S s
int i


void S::foo()
do_something(m->i)
}
 
Thank you. A well placed #include solved this
You never see this type of thing in books do you?
 
Back
Top