Questions tagged [template-classes]
184 questions
0
votes
0 answers
c++ Call method of template class
I´ve created a template class an initialized it.
Now I wanna call a method from this class but I get a compiler error.
(With the Function TemporaryFunctionForSimulator I successfully split the template class in *.h and *.cpp.
So that is NOT THE…

alexander-fire
- 1,082
- 4
- 27
- 52
0
votes
1 answer
c++ store functor in class
I´ve created the following Event class:
Event.h
#ifndef EVENT_H
#define EVENT_H
#include
template
class Event
{
public:
T fnktptr; //Error: field ‘Event::fnktptr’ invalidly declared function type
…

alexander-fire
- 1,082
- 4
- 27
- 52
0
votes
1 answer
restrict-pointer-type template arguments and overriding virtual methods of a templated base class
The following should, I believe, compile and link, but doesn't:
template
class A {
public:
virtual int foo(S arg) = 0;
virtual ~A() { }
};
class B : public A
{
public:
int foo(int* __restrict__ arg) override…

einpoklum
- 118,144
- 57
- 340
- 684
0
votes
3 answers
Const reference wrapper from reference wrapper
Consider the following reference wrapper:
template
struct wrapper
{
wrapper(T& x): reference{x} {}
void set(const T& x) {reference = x;}
T& get() const {return reference;}
T& reference;
};
I am wondering:
How to declare a…

Vincent
- 57,703
- 61
- 205
- 388
0
votes
1 answer
link error with illegal call
CUtil::input(command);
I wrote the code above in "main.cpp"
and I made a header file for that code, which is written below.
But I received the following error message:
C2352: 'class::function' : illegal call of non-static member…

윤성필
- 85
- 1
- 1
- 7
0
votes
1 answer
C++ templated class "no appropriate default constructor available"
I created a Node class for a linked list in C++:
template class Node {
public:
T val;
Node* next;
Node(T val) {
this->val = val;
this->next = nullptr;
}
~Node() {
Node* temp = this->next;
…

Amit
- 5,924
- 7
- 46
- 94
0
votes
2 answers
template class instantiation in another class in c++
I have a template class that when I instantiate in main doesn't have any issues but when i try instantiating the same in another class is giving issues. can someone please enlighten me on the solution for…

Harish
- 23
- 5
0
votes
2 answers
Eliminating the unwanted case for a template class
I am using template class type datatypes as arguments for a method of a class. In that method, I am calculating the difference of the arguments and printing it. This is just a sample code from the actual project.
Header.h
#ifndef Header_h
#define…

skm
- 5,015
- 8
- 43
- 104
0
votes
0 answers
error with pointer_name is not declared in this scope
I have made declaration of pointer first, last & counter made in the header of template base class,but when header is included in the definition of derived class, it occurs error stated that first,last & counter is not declared in this scope. But…
0
votes
1 answer
Static member of template base class doesn't get exported to shared library
I have a class 'ModelManager' which is derived from a template class 'TModelManager'. Their declaration is as follows:
template
class TModelManager
{
protected:
static…

Silverlan
- 2,783
- 3
- 31
- 66
0
votes
1 answer
Is there any way to print template class object
I am trying to create template class for storing different values, for instance, I have a list, which can hold value of any type.
template
class LinkedNode
{
private:
LinkedNode* next;
LinkedNode* previous;
T data;
Is there…
user4602510
0
votes
2 answers
How do I create a makefile with only a main file and template header (C++)
I'm trying to create a makefile that will compile two files:
-main.cpp
-queue.h
Inside of the header file I have the a full implementation of a template Queue class. The main file includes the header file.
I can test this code in the terminal (on a…

GusGus
- 230
- 6
- 16
0
votes
0 answers
overloaded operator% of normal class nested in template class, defined outside classes
I have problem with defining operator% outside my template class. I solved this problem doing it inside, but I would like to know why it doesn't work the other way.
Here is my code:
namespace std{
class vector{};class deque{};class list{};class…

Adam Gabryś
- 11
- 4
0
votes
2 answers
How to correctly use a nested class of a template class?
all!
I am trying to implement a simple template class binary search tree.
I run into a couple problem with the definitions of functions.
The following is my BST class code
#ifndef BINARY_SEARCH_TREE_H
#define BINARY_SEARCH_TREE_H
#include…

user3377437
- 183
- 1
- 2
- 9
0
votes
0 answers
g++ shows "undefined reference" for methods of a template class, but they match their prototypes
I have a template class defined like this:
closedlist.h
template
class ClosedList
{
public:
// …
bool isEmpty () const { return (size() == 0); }
T first () const;
T pop_first ();
void push_back (const T &value);
…

msrd0
- 7,816
- 9
- 47
- 82