All Questions

1240
votes
13answers
318135 views

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? ...
823
votes
5answers
102588 views

Where and why do I have to put the "template" and "typename" keywords?

In templates, where and why do I have to put typename and template on dependent names? What exactly are dependent names anyway? I have the following code: template <typename T, typename Tail> /...
372
votes
23answers
99709 views

Is it possible to write a template to check for a function's existence?

Is it possible to write a template that changes behavior depending on if a certain member function is defined on a class? Here's a simple example of what I would want to write: template<class T&g...
318
votes
7answers
30107 views

Pretty-print C++ STL containers

Please take note of the updates at the end of this post. Update: I have created a public project on GitHub for this library! I would like to have a single template that once and for all takes care...
117
votes
3answers
16143 views

Why do I have to access template base class members through the this pointer?

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this->x. Why? template <typename T> class base { protected: ...
199
votes
30answers
147340 views

How can I add reflection to a C++ application?

I'd like to be able to introspect a C++ class for its name, contents (i.e. members and their types) etc. I'm talking native C++ here, not managed C++, which has reflection. I realise C++ supplies some...
279
votes
5answers
68727 views

What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

Can some one please describe the usage of the following characters which is used in ERB file: <% %> <%= %> <% -%> <%# %> what's the usage of each one ?
37
votes
4answers
11242 views

Why should the implementation and the declaration of a template class be in the same header file?

Why should the implementation and the declaration of a template class be in the same header file? Could any of you explain it by example?
331
votes
10answers
212352 views

Storing C++ template function definitions in a .CPP file

I have some template code that I would prefer to have stored in a CPP file instead of inline in the header. I know this can be done as long as you know which template types will be used. For example...
91
votes
13answers
44526 views

Check if a class has a member function of a given signature

I'm asking for a template trick to detect if a class has a specific member function of a given signature. The problem is similar to the one cited here http://www.gotw.ca/gotw/071.htm but not the same...

Previous Next