Linked Questions
14 questions linked to/from What does template <unsigned int N> mean?
4 votes
3 answers
11k views
templates <int T> C++ [duplicate]
What does it mean to define a template with template <int N>, I read this from an example in a book: typedef map<int, double> row; template <int N> struct matrix; { map <int, ...
1 vote
2 answers
602 views
Non-Type parameters for templates [duplicate]
Possible Duplicate: What does template <unsigned int N> mean? Hi ! Are non-type template parameters and constants same ? Do the following code work because template parameter cannot be ...
1 vote
2 answers
111 views
Is this a template specialization? [duplicate]
template <int parameter> class MyClass is the above a template specialization? I don't think so but I'm unsure of it, I didn't know templates could receive arguments as functions.. where do ...
0 votes
2 answers
119 views
What does that mean in C++ templates? [duplicate]
Say that we have the following: template <class T, int i> I understand that T will be whatever type being passed to some function. But, what does the int i portion mean? Thanks.
26 votes
5 answers
31k views
calculating factorial using template meta-programming
I do not understand how this piece of code (from Wikipedia) works: template <int N> struct Factorial { enum { value = N * Factorial<N - 1>::value }; }; template <> struct ...
8 votes
2 answers
37k views
How to write a template function that takes an array and an int specifying array size
For a university exercise, I have been asked to write a template function "print();", which takes two arguments, 1: an array of a generic type, and 2: an int specifying the size of the array. The ...
14 votes
2 answers
910 views
Why can a void method in C++ return a void value, but in other languages it cannot?
This program compiles and runs in C++ but doesn't in a number of different languages, like Java and C#. #include <iostream> using namespace std; void foo2() { cout << "foo 2.\n"; } ...
2 votes
4 answers
4k views
Factory method returning an concrete instantiation of a C++ template class
I have a class template <unsigned int N> class StaticVector { // stuff }; How can I declare and define in this class a static factory method returning a StaticVector<3> object, sth like ...
0 votes
3 answers
700 views
fundamental types as a function templates parameters
I thought that a function template parameters are declared only by class identifiers, for example: template<class T1, class T2> void fun(T1 a, T2 b){} but I found other example where ...
2 votes
2 answers
459 views
How to initialize a static member of a parametrized-template class
I don't think my question is a duplicate of this one. what I try to do: template<const char* szFunctionName> class CReentranceLock { public: CReentranceLock(){} ~CReentranceLock(){} ...
0 votes
1 answer
344 views
user select array type from menu c++
I have created a generic array-like template to create arrays of different types. Now I need to get user input from a menu about which type of array they are building. I tried having the user enter a ...
0 votes
1 answer
95 views
why we need template <int N> since we have class initialization
recently I knew a new template usage like below template <unsigned int N> I saw the answer here What does template <unsigned int N> mean? It showed several examples includes: template<...
-2 votes
2 answers
78 views
About template function
I have a question about template function. This is my first time using template. I may lack of some basis. I am confusing about the type of variables I should use. What is the meaning of int N after ...
0 votes
0 answers
64 views
Int-parameterized template with hexadecimal value : link error "1 unresolved externals"
When I specialize an int-templated function with a negative value defined in hexadecimal, Visual Studio 2010 give me a strange "1 unresolve externals" link error. Still it works fine if: I define the ...