Jump to content
  • Advertisement
Sign in to follow this  
Harry Hunt

[C++] template parameter for static methods

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

Hi! I was wondering if the following can be done: I have a regular non-templated class, let's call it MyClass. Now I want this class to remain non-templated, but I want it to have a static method that takes a template parameter, so something like this:
class MyClass
{
public:
  template <typename T>
  static MyClass Create(T value);
};


This obviously won't compileEDIT: Wait a second, this does compile, but I was wondering if there is a solution that will, but is it legal C++? Thanks a bunch in advance!

Share this post


Link to post
Share on other sites
Advertisement
Sure, it's legal. Static functions act almost identical to global non-member functions, except where scoping is concerned.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!