Questions tagged [template-classes]
184 questions
-1
votes
2 answers
How to insert a new node into a binary tree c++ while using a template class for ItemType. (I am new to c++)
So I am not really sure how the Template Class and the ItemType are interacting here. Should I just be changing root->data to the value? I keep getting a seg fault when doing that. So I figured I would have to create a new node and then assign that…

jose reyes
- 1,533
- 1
- 13
- 17
-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
what is the purpose of template class in c++
I cannot understand what is template class used for?
I am new to c++. Can I get a detail explanation.
// constructing unordered_sets
#include
#include
#include
template
T cmerge (T a, T b) { T t(a);…

Akash Chandra
- 375
- 1
- 4
- 13
-1
votes
3 answers
Loop to add all 26 letters into s using set Template Class
I'm studying for a exam next week and I've come across a question in my book that I can't get to work. Says that suppose set s; is declared now write a loop to insert all 26 letters into s.
What I've got is
for(int i = 0; i < 26; i++)
{
…

chanse.s
- 13
- 4
-1
votes
1 answer
No matching function call Strange error
#include
using namespace std;
const int size=4;
template
class vector
{
datatype *v;
public:
vector()
{
v=new datatype[size];
…

user5501265
- 39
- 1
- 8
-1
votes
2 answers
non template function in a template class
I was wondering if there is a way to place a non template function within a template class.
Simply put I don't want to compiler to repeat the function for each type since the function is only manipulating pointers hence there is no type. Is this…

user3813249
- 313
- 1
- 4
- 12
-1
votes
2 answers
Why template class not working properly for double?
I have the following code:
#include
#include
#include
using namespace std;
template class Stack
{
private:
T a[1001];
int i=0,j;
public:
void pop(void)
{
a[i-1]=0.0;
…

MD. Khairul Basar
- 4,976
- 14
- 41
- 59
-1
votes
1 answer
c++: unable to match function definition to an existing declaration
HERE IS WHERE HOW I DECLARED IT IN THE PUBLIC OF "template"
void print();
HERE IS TO PRINT
template
T XArray::print()
{
for ( int i = 0; i < size; ++i)
cout << Array[i] << " ";
cout << "\n\n";
}
I don't know what I'm…

bonafide
- 368
- 4
- 25
-1
votes
2 answers
Template class T
If I have
template class Vector
public:
Vector(const Vector& bla);
How can I use it outside the .h file?
I´ve tried Vector::Vector but that doesn´t work.
some part of the .h file
Vector();
Vector(int size, T value =…

user3399655
- 33
- 8
-1
votes
1 answer
Why is this very simple constructor causing a seg fault?
This is embarrassing, but I'm a little rusty on my C++ and for the life of me I can't see why this code is causing a segmentation fault. The weird this is that several iterations ago it seemed to work fine. I don't even know what I'm doing…

SemperCallide
- 1,950
- 6
- 26
- 42
-2
votes
1 answer
c++ Operator overloading for template vector struct
I am creating a template Vector struct and trying to overload some arithmetic operations. However, even when I did overload the operators, I'm getting no match errors. Code shown below.
In my Vector.hpp file I have the following code:
template…

Yutong Huang
- 3
- 1
-2
votes
1 answer
Class template instantiation errors
The .hpp file below compiles without any errors or warnings:
#ifndef CODE_HPP
#define CODE_HPP
#include
#include
using std::vector;
using std::array;
//stack template definition
template>
class…

Vinod
- 925
- 8
- 9
-2
votes
1 answer
Ignore template argument to provide swap function
i want to provide a swap function for my template class. Here's a simplified version:
template
class ExampleClass
{
public:
ExampleClass() : data(size) {}
void swap(ExampleClass& _Right)
{
…
user9278166
-2
votes
1 answer
In my template class example, “segmentation fault (core dumped)” error occurs
In my code, I want to create a cookie and add it to a shop by sending the cookie to shop constructor as parameter. It adds the cookie but give segmentation fault error.
I get the result:
Chocolate Cookie 50 180
Segmentation fault (core dumped)!
I…

Murat
- 1
- 3
-2
votes
1 answer
Base class pointer for a template class that uses template parameter in member data
For the following template class
template class Arbitrary {
protected:
vector ObjectArray;
public:
Arbitrary(){}
};
I want to be able to have a vector of base class pointers, I know I need to use an interface class but I…

Toby
- 19
- 3