Jump to content

  • Log In with Google      Sign In   
  • Create Account


templates and default values by default?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Nicholas1991   Members   -  Reputation: 118

Like
0Likes
Like

Posted 19 July 2010 - 07:08 AM

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.

Sponsor:

#2 LorenzoGatti   Crossbones+   -  Reputation: 2628

Like
0Likes
Like

Posted 19 July 2010 - 11:08 PM

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?

#3 phresnel   Members   -  Reputation: 949

Like
0Likes
Like

Posted 19 July 2010 - 11:28 PM

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.

#4 Nicholas1991   Members   -  Reputation: 118

Like
0Likes
Like

Posted 20 July 2010 - 08:17 AM

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.

#5 Sneftel   Senior Moderators   -  Reputation: 1776

Like
0Likes
Like

Posted 20 July 2010 - 08:23 AM

Moved to the For Beginners forum.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS