Questions tagged [template-classes]
184 questions
1
vote
2 answers
How can I make a template class within a template class
I am working on recreating the forward linked list class so I can better understand pointers. I have hit a roadblock, I have a template class called forward_list. Within this class in the private section I have another class which I want to have the…

Breadleaf
- 161
- 4
1
vote
2 answers
How to pass a template class as a function argument without C7568 error
C++ newbie here. I'm pretty sure there's an easy and obvious solution to this problem, but even after reading through dozens of similar Q&As here, I haven't got closer to it. But here's my problem:
I have a template class:
template
struct…

Attila Fenyvesi
- 95
- 2
- 8
1
vote
1 answer
template copy of derived class
I'm making copy of template class that can contain pointer on object or pointer of derived class. I tried with allocation on heap but it continuously making object of main class, doesn't matter is it of derived or main class. How can I fix it. Code…

Nikola Nikolic
- 121
- 5
1
vote
1 answer
How to obtain the return type of a function passed into a templated function or class?
How does one obtain the return type of a function (passed into a higher-order function/class) in this fashion:
template
auto DoSomething(F&& func) -> /* whatever type func returns */
{
// whatever...
return /* something that is…

Sappy B.
- 38
- 5
1
vote
1 answer
C++ program compiles in Visual Studio 2010 but not Mingw
The program below compiles in VS 2010, but not in a recent version of Mingw. Mingw gives me the error "conversion from int to non-scalar type 'tempClass(it)' requested". Class "it" is just a simple class to use in the template for the purpose of…

Humid Morning
- 5
- 3
1
vote
1 answer
Rvalue and Move Semantics with Unique Pointer: error for object 0x7ffee5c7b670: pointer being freed was not allocated
I am trying to understand how unique pointers and move semantics. Now, I have created a dummy example below to show what the issue is. My question is, why does this code throw a pointer being freed was not allocated error?:
#include…

finite_diffidence
- 893
- 2
- 11
- 20
1
vote
1 answer
Can't explicitly instantiate a templated class
In "header.h"
template struct Foo
{
void func();
};
In "Source2.cpp"
#include "Header.h"
#include
template
void Foo::func()
{
T a = 5;
std::cout << a;;
}
In "Source1.cpp"
#include…

Zebrafish
- 11,682
- 3
- 43
- 119
1
vote
2 answers
Class vs. function template specialization
I only recently learned about partial template specialization in C++ from here, and it perfectly solved a problem where I needed a template class to behave differently for pointers and non-pointers. A simplified example is:
// main.cpp
template…

StoneThrow
- 5,314
- 4
- 44
- 86
1
vote
0 answers
Correct way of structuring CMake based project with Template class
I am having following compilation issue with my project with template class
Undefined symbols for architecture x86_64:
"Node, std::__1::allocator > >::Node(int,…

Brandon Lee
- 695
- 1
- 10
- 22
1
vote
0 answers
What is the difference between a template class design pattern and generic template class in a programming language like Java?
I am taking this basic course in design patterns that explains "Template-And-Hook Patterns" as an introduction by starting with the "Template Method Pattern" then goes a little bit complex into "Template Class Patterns" and finally the "Generic…

Ahmed Samy
- 1,006
- 2
- 11
- 24
1
vote
1 answer
How to derive abstract template classes, with template-types as function parameters (C++11)
I've been assigned to write a class "binaryExpressionTree" which is derived from the abstract template class "binaryTreeType." binaryExpressionTree is of type String. As part of the assignment, I have to override these 3 virtual functions from…

Ian Crovella
- 45
- 1
- 5
1
vote
2 answers
How to extract the types passed in template parameters?
In the below code, I want to replace "something" with something that will allow me to declare the type of 'f' as the second parameter passed in C (while passing C to M's template), i.e., float here.
#include
using namespace…

Jeevesh Juneja
- 212
- 2
- 9
1
vote
1 answer
Error initializing array size using const static variable of class template
template>
class stack{
...
friend class stack_array;
};
template, typename K = stack>
class stack_array{
...
static const size_t max_elem;
array

Vinod
- 925
- 8
- 9
1
vote
0 answers
Compiler error related to public method granting access to private class member
Given the following class template definitions
template
class node{
private:
T& data;
shared_ptr>& next;
public:
T& get_data(void);
shared_ptr>& get_next (void);
public:
…

Vinod
- 925
- 8
- 9
1
vote
1 answer
How to properly define template function in template class with a template class as a template parameter
I have a problem with defining class-function when class have another class as a template parameter.
the exception is "template argument list should correspond to a template parameter list"
template >
class…

Александр Кушниренко
- 210
- 1
- 12