Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBluefirehawk

Posted 07 August 2012 - 08:51 AM

You should generally prefer a forward declaration if that's enough (i.e., if you are only going to declare pointers or references to the class), especially in header files. That way compiling a module won't require reading an extra header file, and a change in the header file will trigger recompilation of fewer modules.


Okeeey... so for example the Observable.h would look like this:
class Observable
{
class Message;
private:
	...
	void NotifyObservers(Message me);
	...
}
this would be the best way to do it (considering includes and not the public function).
but then under the same rules it would make sense to just forward declare on the Observer.h as well, and now I have never included the Message.h and the program will probably not link correctly.

In other words, when do I ever use an object in the header file and do more with it than just declaringreference/pointers? Thats what the cpp files are for, i thought.
Thanks for the reply, but it's still not very clear to me.

#3Bluefirehawk

Posted 07 August 2012 - 08:51 AM

You should generally prefer a forward declaration if that's enough (i.e., if you are only going to declare pointers or references to the class), especially in header files. That way compiling a module won't require reading an extra header file, and a change in the header file will trigger recompilation of fewer modules.


Okeeey... so for example the Observable.h
class Observable
{
class Message;
private:
	...
	void NotifyObservers(Message me);
	...
}
this would be the best way to do it (considering includes and not the public function).
but then under the same rules it would make sense to just forward declare on the Observer.h as well, and now I have never included the Message.h and the program will probably not link correctly.

In other words, when do I ever use an object in the header file and do more with it than just declaringreference/pointers? Thats what the cpp files are for, i thought.
Thanks for the reply, but it's still not very clear to me.

#2Bluefirehawk

Posted 07 August 2012 - 08:50 AM

You should generally prefer a forward declaration if that's enough (i.e., if you are only going to declare pointers or references to the class), especially in header files. That way compiling a module won't require reading an extra header file, and a change in the header file will trigger recompilation of fewer modules.


Okeeey... so for example the Observable.h
class Observable
{
class Message;
private:
	...
	void NotifyObservers(Message me);
	...
}
this would be the best way to do it (considering includes and not the public function).
but then under the same rules it would make sense to just forward declare on the Observer.h as well, and now I have never included the Message.h and the program will probably not link correctly.

In other words, when do I ever use an object in the header file just to declare reference/pointers?
Thanks for the reply, but it's still not very clear to me.

#1Bluefirehawk

Posted 07 August 2012 - 08:49 AM

You should generally prefer a forward declaration if that's enough (i.e., if you are only going to declare pointers or references to the class), especially in header files. That way compiling a module won't require reading an extra header file, and a change in the header file will trigger recompilation of fewer modules.


Okeeey... so for example the Observable.h
class Observable
{
class Message;
public:
    ...
    void NotifyObservers(Message me);
    ...
}
this would be the best way to do it (considering includes and not the public function).
but then under the same rules it would make sense to just forward declare on the Observer.h as well, and now I have never included the Message.h and the program will probably not link correctly.

In other words, when do I ever use an object in the header file just to declare reference/pointers?
Thanks for the reply, but it's still not very clear to me.

PARTNERS