Questions tagged [template-classes]

184 questions
0
votes
2 answers

C++ created multiple struct with class template

I want to create typesafe structures that are basically identical but have different types so that they require different function signatures. struct A { Time t; void doStuff(const A&); A getStuff(); }; struct B { Time t; void…
chrise
  • 4,039
  • 3
  • 39
  • 74
0
votes
1 answer

C++ Template Class Dynamic Array of Pointers to Arrays

I am making a templated matrix class in C++. To create this class I am creating an array of pointers, and those pointers point to dynamic arrays. So far I have: template class Matrix { public: //constructor …
Gene
  • 104
  • 15
0
votes
1 answer

C++ Can you make an iterator of a template class?

I'm working on a class project and for it for it we have to make a template class that is derived from vector and then be able to add and remove elements from it. I thought I would make and iterator of the class since it is a vector I thought I…
Evin
  • 15
  • 4
0
votes
1 answer

In my template class example, Even if I dont define add method, it addstake "segmentation fault (core dumped)" error

!! Note: I edited the question many times after the answers. But the question below is the first question and the first answer is a helpful answer. Please do not confuse by some comments. They are written after I changed my question many times. I…
Murat
  • 1
  • 3
0
votes
1 answer

Template class giving error with primitive data types

Gives "non-static variable this cannot be referenced from a static context" This is the code below for template class public class BiHashMap{ private final Map> mMap; public BiHashMap() { mMap = new…
0
votes
1 answer

How to elegantly restrict a template argument to be a `>`?

How to restrict a template argument of Wrapper to be a Wrapper> elegantly? Don't break content assist (Visual Studio). High readability. Not use a hacky approach. For some reasons, most solution love to hack. Make it obvious…
0
votes
1 answer

trying to understand how Template Class works

I have done this assignment as best as i understood it but i am pretty sure there are radical problems. I'll be Looking forward to your comments on how to make it better. The problem definition is as follows: Two classes. XBoxGame and…
ArashDe
  • 23
  • 1
  • 7
0
votes
1 answer

Method as default parameter for a method

I'm currently working on a Set-class for a c++ course which is a derivation from vector. At a point I came to the point where I needed to implement a function called index() which will obviously return (if the set contains it) the index of a…
Philipp Zettl
  • 177
  • 1
  • 3
  • 17
0
votes
0 answers

c++ template class operator<< overloading

I am having problem when trying to overload the << operator of a template class, where I receive the error LNK2019: unresolved external symbol error. The code is as follows: template struct subvec { T vec[NDIMS]; ... friend…
user138668
  • 161
  • 4
0
votes
1 answer

Interfacing and Inheritage of template classes in c++

I have a problem with a project using template class inheritance. The idea is to have an agent that has a pointer to a msgtype. The msgtypes can differ, that's why a template class comes into game. The idea is to store the different message types…
DentOpt
  • 77
  • 1
  • 6
0
votes
2 answers

Variadic template class: Is it possible to implement one unique member function per variadic template argument?

I'm using the Visitor pattern to implement reflection without relying on RTTI. My problem is: I want to implement a Visitor which can cast different classes DerivedItem1, DerivedItem2, etc. derived from the same BaseItem class, to this BaseItem…
0
votes
2 answers

Template array of pointers c++?

Hello guys in my c++ program I have four classes (A,B,C,D) A is the base class B inherits from A C inherits from A D inherits from B All of them are template classes template and each of them has a print method that prints its private…
0
votes
1 answer

How do you initialize template class members that uses other template classes?

I'm having trouble correctly setting up and accessing my member functions of a class. This node class is being used to build a Max Heap Tree. However, when the tree is being initialized, I'm getting garbage data and not what I am initializing it to.…
luigi741
  • 5
  • 1
0
votes
0 answers

private static data member + template class

I have this code: in a.h file: #ifndef A_H_ #define A_H_ class Class_Hierarchy{ public: std::map> map; Class_Hierarchy(){ std::map> map; } …
Loay
  • 483
  • 3
  • 18
0
votes
1 answer

c++ operator overloading in template class

I´ve developed an template class. Now I want to overload the lower than operator. I tried it normally, like with a normal class, but it doesn´t work. Event.h #ifndef EVENT_H #define EVENT_H #include #include template
alexander-fire
  • 1,082
  • 4
  • 27
  • 52