Linked Questions

781 votes
6 answers
301k views

What is the difference between "typename" and "class" template parameters?

For templates I have seen both declarations: template < typename T > template < class T > What's the difference? And what exactly do those keywords mean in the following example (taken ...
Mat's user avatar
  • 11.7k
13 votes
2 answers
8k views

What is the difference between "template <class T>" and "template <typename T>"? [duplicate]

Possible Duplicate: Use 'class' or 'typename' for template parameters? I see two different template class declarations: template <class T> class SampleClass1 { // ... };...
hkBattousai's user avatar
  • 10.8k
496 votes
29 answers
383k views

What are the differences between struct and class in C++?

This question was already asked in the context of C#/.Net. Now I'd like to learn the differences between a struct and a class in C++. Please discuss the technical differences as well as reasons for ...
palm3D's user avatar
  • 8,060
41 votes
2 answers
8k views

Is "enum class" a class type in C++?

I read about enumeration declaration in C++ using cppreference. Then I have made Enum class and check whether it is a class type or not using std::is_class. #include <iostream> enum class ...
msc's user avatar
  • 33.9k
11 votes
3 answers
13k views

Declaring a struct in a template class, undefined for member functions

I'm currently trying to implement a sort algorithm in a list template class using node structures private to the list class. I'm using a few private recursive functions which return a pointer to a ...
Lindenk's user avatar
  • 495
9 votes
3 answers
9k views

Template class with template function

Can anyone tell what is wrong with this piece of code? template<class X> class C { public: template<class Y> void f(Y); // line 4 }; template<class X, class Y> void C<X>::...
freitass's user avatar
  • 6,622
4 votes
6 answers
6k views

"error: no matching function for call to"

I was on codepad and I was trying to build up my skills using C++. I'd never used templates much before, so I tried looking into how to use them. The code below is the result, and unfortunately, it ...
awsumpwner27's user avatar
9 votes
4 answers
3k views

Better C++ syntax for template base class typedefs and functions?

I have code that compiles fine with VC9 (Microsoft Visual C++ 2008 SP1) but not with GCC 4.2 (on Mac, if that matters). If I pile on enough qualifiers and keywords I can force it to work in GCC but ...
jwfearn's user avatar
  • 29.2k
11 votes
2 answers
3k views

Why do both struct and class exist in C++?

As we know, struct and class are interchangeable in many places in the language. Confusingly, the keywords themselves do not necessarily correspond to the language used in the standard. For example, ...
user5817092's user avatar
1 vote
3 answers
533 views

Compiler compile a 'io_service_' variable show as : cannot appear in a constant-expression

I created a ServerService namespace for containing a class name server_datetime. Server_datetime class as tutorial at Boost examples, but I improved server_datetime class by using template parameter ...
R.Chatsiri's user avatar
0 votes
3 answers
445 views

Instantiation of generic lambda

The following does not compile: #include <iostream> #include <type_traits> template <class F, class G> auto static_if (std::true_type, F && f, G && g) { return ...
JohnB's user avatar
  • 13.6k
1 vote
4 answers
1k views

How to distinguish data structure template and function template in C++?

I have learned that data structures can be created using templates in the following way: template<typename T> struct X { T weight; int age; }; The functions can also use templates in the ...
Roman's user avatar
  • 128k
0 votes
2 answers
873 views

Template class with iterator to a STL container

I want to create a template class which has an iterator of a STL container as a member. That is how far I got: #include <iostream> #include <vector> using namespace std; template<...
newandlost's user avatar
3 votes
4 answers
244 views

templated function argument in C++14

This code does not compile, not even under C++14, because of problems with template type deduction. What is the least inelegant workaround? #include <vector> #include <functional> #...
Joachim W's user avatar
  • 7,644
2 votes
2 answers
144 views

Passing a std container to a templated class

Why doesn't this work? template <typename T, typename U> class TSContainer { private: U<T> container; }; called as: TSContainer<int, std::vector> ts; I think a ...
Jonathan Winks's user avatar

15 30 50 per page