Jump to content
  • Advertisement
Sign in to follow this  

Forward Declaration of Template Class

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the library I'm currently building, I'm trying to avoid including header files in other header files. It's worked so far using forward declaring of other classes, and then simply including those headers in the .cpp file. However, this doesn't seem to work for me with template classes. Here's what I have code wise:

	template <typename T> 
		class Singleton;
	class LogManager : public Singleton<LogManager>

However when compiling I get a couple errors:
LogManager.h:25: error: declaration of 'struct Island::Singleton<Island::LogManager>'
LogManager.h:27: error: invalid use of undefined type 'struct Island::Singleton<Island::LogManager>'

where line 25 is where I'm trying to declare the Singleton class and 27 then is when I'm trying to use it. Being that I'm deriving from the Singleton class, is that the reason I can't use forward declaring? Or is there another reason? If it matters I'm using Xcode on OS X, newest version. I think it uses GCC 4 but I might be mistaken.

Share this post

Link to post
Share on other sites
Forward declaration will not suffice. You can only inherit from a fully defined class. This is independent of the class being a class template or a non-template class.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!