Jump to content
  • Advertisement
Sign in to follow this  
Nicholas1991

templates and default values by default?

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

Hello everyone,

with the help of a book and online tutorials I try to get into game programming. However, I'm still new to C++ so while reading and programming a little with C++ I had some trouble with templates.

That's what I find in the book I'm reading:


template <class blub, bool bSomething, typename someType>
class MyClass {
public:
MyClass();
~MyClass();
};

template <class blub, bool bSomething, typename someType>
MyClass::MyClass()
{
}


And then later:


class NewClass : public MyClass<SOMECLASS>
{
//...
};


Now the compiler obviously complains about missing template arguments, so I just fill in some values and everything works fine. However, it bothers me that throughout the entire book the author leaves out template arguments without defining default ones. I'm a bit worried that my app might show unexpected behaviour because of that. Thus my question wheter or not there is a way that the code as printed in the book works.

Share this post


Link to post
Share on other sites
Advertisement
Either the relevant template definitions with less parameters are omitted as obvious (yuck) or the usage with less parameters is sloppy, untested wrong code (double yuck).

Seeing the mixture of "class" and "typename" template parameters the latter seems more likely, which begs the question: what book are you reading?

Share this post


Link to post
Share on other sites
In any case, if you are interested in serious C++ template programming, get a copy of the template bible "C++ Templates: The Complete Guide" by Vandevoorde and Josuttis. It will also show you many guru'esque parts of C++ that are not bounded to templates, like name lookup.

Share this post


Link to post
Share on other sites
I'm reading "Spieleprogrammierung mit DirectX 11 und C++" by Susanne Wigard. C++ is compared to java a pain in the... (personal opinion) But for me C++ seemed to be the best way to program 3D Games. Anyways, since the classes that leave out some template parameters do not use them at all it should be safe to fill in some random stuff. The book is only a guideline for beginners to get to know DirectX and general concepts so most likely parts of the code will be changed, expanded or removed later when I have some idea of how a game engine is structured.

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!