|
-
July 12th, 2009, 03:56 PM
#1
C++ Templates: The Complete Guide
Hello,
I purchased this book hoping to gain a further understanding in templates. But my issue is that, a lot of the code that the book says WONT compile, ... does. Such as the following -
Code:
// maximum of two values of any type
template <typename T>
inline T const& max (T const& a, T const& b)
{
return a < b ? b : a;
}
// maximum of three values of any type
template <typename T>
inline T const& max (T const& a, T const& b, T const& c)
{
return max (max(a,b), c); // uses the template version even for ints
} // because the following declaration comes
// too late:
// maximum of two int values
inline int const& max (int const& a, int const& b)
{
return a < b ? b : a;
}
Which calls the int function for me on VS2008, CodeBlocks and DevC++. Where i had the latter 2 set to the GCC compiler. Other issues are examples where although the book says i need to use typename for some dependant type, VS2008 doesnt require it.
Im not sure if this is due to the book being out of date or what. But i was wondering if you could give me some advice as to how i should continue. Should i keep reading? is there some other more up to date material that these compilers are conforming too?
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|