All Questions

822
votes
5answers
102515 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> /...
23
votes
2answers
678 views

static_assert dependent on non-type template parameter (different behavior on gcc and clang)

template <int answer> struct Hitchhiker { static_assert(sizeof(answer) != sizeof(answer), "Invalid answer"); }; template <> struct Hitchhiker<42> {}; While trying to disable gen...
8
votes
2answers
11682 views

calling template function of template base class

Possible Duplicate: Where and why do I have to put the “template” and “typename” keywords? Here's the code: template<typename T> class base { public: virt...
5
votes
2answers
334 views

Visual C++ Compiler allows dependent-name as a type without "typename"?

Today one of my friends told me that the following code compiles well on his Visual Studio 2008: #include <vector> struct A { static int const const_iterator = 100; }; int i; template <typ...
15
votes
1answers
218 views

What is the rule that allows `this->` to access members of dependent base classes?

As we know, the code below is ill-formed because the member x is in a dependent base class. However, changing x to this->x on the indicated line would fix the error. template <typename T> st...
9
votes
5answers
2942 views

multiple nested dependent names - where to stick the typename keyword?

This question was inspired by this other question. While trying to answer that question, I understood that I have a lot of questions myself. So... Consider the following: struct S1 { enum { value...
7
votes
1answers
522 views

Compiler error when using integer as template parameter

What is wrong with the following piece of code? template<typename X> struct A { template<int N> int foo() const { return N; } }; template<typen...
9
votes
2answers
3115 views

Accessing types from dependent base classes

Does anyone know why using-declarations don't seem to work for importing type names from dependent base classes? They work for member variables and functions, but at least in GCC 4.3, they seem to be ...
4
votes
0answers
81 views

Derived template-class access to base-class member-data: for dependent name

In the following long list of codes, please look for three places: // "this->" can be omitted before first data[0] and // Compile error, if "this->" is omitted before first data[0] and ...
3
votes
1answers
200 views

dependent types with variadic templates

Can you see anything wrong with this function declaration? template<typename... Containers> std::tuple<typename Containers::value_type...> foo(const Containers &...args); When I try...

Previous Next