Jump to content
  • Advertisement
Sign in to follow this  

C# template class

This topic is 3033 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 want to add a template class to my project, but i'm not really sure how to do this. I'm using XNA in which you can load a model in two different ways: Model model = Content.Load<Model>("modelname"); or SkinnedModel = Content.Load<SkinnedModel>("modelname"); So i can use Model or SkinnedModel. Now i thought templates would come in handy here. But i'm not sure if the following is possible. How would something like this work: class ModelType<T> { T t; public void LoadModel <T> ( string modelname ) { Content.Load<t>(modelname); } public T getModel ( ) { return t; //return the Model or SkinnedModel. Depends what was created } } So i can use it in a way like this (not sure how it works)
//Somewhere in my main function
ModelType mymodel = new ModelType<SkinnedModel>("model");
somefunc ( mymodel );

public void somefunc ( ModelType model )
    //do stuff with model
    //So this way it shouldn't matter if the ModelType is 'Model' or 'SkinnedModel'
In this case i passed SkinnedModel as ModelType to 'somefunc()' but it should also work if i passed 'Model' as ModelType to that function. That's what templates are for right?? If so, could someone please help me out with this?? Thanks for any help.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!