Functions that serve as a pattern for creating other similar functions. The basic idea behind template functions is to create a function without having to specify the exact type(s) of some or all of the variables.
Questions tagged [template-function]
121 questions
0
votes
1 answer
Return an iterator to an STL container from a template function
I was trying to return an iterator to a vector from a template function (not yet a template class member--I'm still writing that). The compiler kept giving me errors (copied below to to facilitate Google searches). I knew basically what the…

riderBill
- 818
- 9
- 16
0
votes
0 answers
about default template argument in function template
I understood that in C++11 it is possible to have a default in the template arguments of a template function. Until now it was allowed only for classes.
I always thought that putting a default in a template argument in C++11 would mean something…

Abruzzo Forte e Gentile
- 14,423
- 28
- 99
- 173
0
votes
1 answer
C++ Function Returning Different Data Types
First, allow me to apologize if the title of this question is vague.
That said, I'm trying to write a function that will return any one of a number of data types (all defined by me) based on conditions within the function. In essence, what I'm…

user3593978
- 37
- 1
- 5
0
votes
4 answers
Template functions and types in C#
Hello I am having some difficulty with setting up a class , because of the types involved.
Here is the Idea:
class A has a private arraylist which is supposed to be filled with instances of class B.
So any instance of class A will have its on…

Sagi2313
- 105
- 1
- 1
- 10
0
votes
2 answers
Template function calls to other functions
I understand the template functions usually are to be declared and defined in header files.
The problem I am having is that my template function makes calls to other functions. The prototypes of those other functions are in the same header file…

mrei
- 121
- 14
0
votes
1 answer
Template function default parameter and type inference
C++
None of these template functions
template void foo(T par = nullptr) {return;} //#1
template void foo(T par = std::nullptr_t(nullptr)) {return;} //#2
template void foo(T par = int(0)) {return;} //#3
allow…

CodeBricks
- 1,771
- 3
- 17
- 37
0
votes
1 answer
Specializing functions with generic return types
I have what I think is a simple question regarding specializing functions with generic return types. I haven't been able to find another post that answers my question, but perhaps that post exists and I'm just not understanding it (or I haven't…

womple
- 171
- 1
- 3
0
votes
1 answer
Templated member function doesn't accept any type of arguments?
I have the following classes:
template
class Parameter
{
TYPE typeValue;
IDENTIFIER ID;
};
template
class ParameterSystem
{
template
void AddParameter(Parameter

ulak blade
- 2,515
- 5
- 37
- 81
0
votes
2 answers
Overload resolution when passing in a function template to another function
I have the following code :
template
void bar(int x, T y)
{
}
void baz(int x, int y)
{
}
template
void foo(void k(T0, T1), T1 t)
{
}
int main()
{
foo(baz, 10); // OK
foo(bar, 10); // ERROR
return…

keveman
- 8,427
- 1
- 38
- 46
-1
votes
1 answer
Is it possible to put implementation of a template member function which calls a static function in its header?
First of all, I have found some seemingly related threads in this forum, but they do not help. For example, 33182246 is about static template member function, but the template member function in my question is not static, and the error therein is…

user5280911
- 723
- 1
- 8
- 21
-1
votes
1 answer
C++ Xcode template function and array as function variabel
Folks,
trying to figure out why Xcode 6.0 doesn't like this syntax
template
int test(array v)
{
int result = 0;
for (int value : v) {
result += value;
}
return result;
}
int main(int argc, const char * argv[])
{
…
-1
votes
2 answers
Multiple templated functions interact
I have been having trouble getting my findNth templated function to use my helper function quicksort. I keep getting "Use of undeclared identifier 'quicksort'" as if there is no matching function call. Any idea what is going on?
#ifndef…

Kylie Moden
- 1,142
- 1
- 11
- 18
-1
votes
1 answer
Weird behaviour in calling template function
I have written the following code:
#include
#include
#include
using namespace std;
template T Min(T a, T b)
{
cout<<"template function: ";
if(a

MD. Khairul Basar
- 4,976
- 14
- 41
- 59
-2
votes
2 answers
C++ - Template function that can return different types?
I'm working on a section of code that allows the user to search by different types (double/string/date(custom class)). This involves a method called readInSearchCriteria() that I have tried to set as a template. I have done some research into…

marcuthh
- 592
- 3
- 16
- 42
-2
votes
2 answers
The meaning of template keyword in the function declaration
What has the meaning the "using of template keyword in the function declaration"?
In this example compiler errors with error: "func" is not a template function.
template
struct Window {
T value;
};
template void func(Window,…

Simon Hong
- 3
- 2