Jump to content
  • Advertisement
Sign in to follow this  
Guthur

Forward declaration on namespaced template class

This topic is 3670 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

I am assuming this is a namespace issue :s Basically why must i do a cast on the following, is it because the forward declaration doesn't have the namespace? is there a way to add it? I some what fear it might not be the namespace and i am doing something really wrong :s Heres some code: (forward declaration then Pointer assigned)
template <typename Data, class Controller > class ResourceHolder;
class Texture2DControl;

class DiffuseMap
{
public:
	DiffuseMap(void);
	~DiffuseMap(void);
	
	void AddDiffuse(const std::string &filename);
private:
	ResourceHolder<ID3D10Texture2D*, Texture2DControl>* TextureRes;
	bool isValid;
};

void DiffuseMap::AddDiffuse(const std::string &filename)
{
	if(!isValid)
	{
		TextureRes = (ResourceHolder<ID3D10Texture2D*, Texture2DControl>*) new TGE_v01::ResourceHolder<ID3D10Texture2D*, Texture2DControl>(filename);
		isValid = true;
	}
}

Share this post


Link to post
Share on other sites
Advertisement
Is your forward declaration in the same namespace as the real class? Otherwise it shouldn't work, and the cast you are doing is probably very dangerous. So if the class ResourceHolder really resides in the TGE_v01 namespace, then the forward declaration should also do that, like this:

namespace TGE_v01
{
template <typename Data, class Controller > class ResourceHolder;
}

Share this post


Link to post
Share on other sites
Perost: Thats exactly what i want thank you very much for clarifying, i should have thought of wrapping it in a namespace. Ya it wasn't feeling safe to me either.

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!