Questions tagged [class-template]

Anything related to C++ class templates, i.e. classes whose definition depends on some parameter according to templates definition rules.

Anything related to C++ class templates, i.e. classes whose definition depends on some parameter according to templates definition rules.

See:

243 questions
0
votes
2 answers

Return a class template with value template arguments from function

Suppose I have a simple template class: template class ConsecutiveMatcher { public: bool operator () (ElementType lhs, ElementType rhs) { return lhs == Element && rhs == Element; …
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
0
votes
2 answers

Class Template + Function Template

when I tried to create a template class as follows: template class Variant { public : std::string toString(); // var.toString() template std::string toString(); // var.toStrint(); protected: …
0
votes
2 answers

How to create a 2D array in C++ using this specific container

I'm trying to port a int a[][] from Java to C++. I'm using this class as a container ArrayRef for ints because it handles references, and the project uses it extensively. In the AbstractReader class I declared const ArrayRef
Andres
  • 2,880
  • 4
  • 32
  • 38
0
votes
1 answer

Can C++ class templates take method names as template parameters?

Just like the title asks, can C++ class templates take method names as template parameters? For instance, template class Foo { public: void T(int bar); };
Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
0
votes
1 answer

Template error in list

I am trying to implement Koch's Snowflake. I have made a generic list, for practice sake, but I am having some issues. #include #include #include #include template class Node { public: T…
-1
votes
1 answer

Non type template argument compiles in msvc but not in clang and gcc

I am learning about non-type template parameters using C++ Primer 5th edition and came to know that: A nontype parameter may be an integral type, or a pointer or (lvalue) reference to an object or to a function type. An argument bound to a nontype…
-1
votes
1 answer

How to restrict generic class method template parameter to certain types?

I have checked out std::enable_if to conditionally compile a member function However it doesn't work for me. I need to restrict T of a class method to some types. template || is_same_v
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
-1
votes
1 answer

Which members are inherited from the template parameter

If we have a class template like template class Field { .... }; Now, if I declared an object of class Field as Field velocityField; So which member functions is inherited form vector to my velocityField
Mohamed Ouda
  • 121
  • 2
-1
votes
1 answer

How to invoke Single argument constructor in this program involving class template?

This is the code I wrote to get started with class templates. #include using namespace std; template class Complex { T *real,*imag; public: Complex(T a) { real=new T; imag=new T; *real=a; *imag=0; …
hcoder
  • 103
  • 11
-1
votes
1 answer

Linked List Function Implementation Help: insertEnd C++

so I implemented the definition for a function insertEnd which inserts a linked list node at the end of a linked list. For the most part, it seems to work on its own, but I seem to have issues when using it in other functions (such as concatenating…
Crowning
  • 167
  • 1
  • 2
  • 10
-1
votes
1 answer

Virtual Method calling another virtual method in a templatized class

I've been reading different questions on this topic, but haven't been able to find one that quite answers what I'm looking for. Here's the pattern of code that I have: class Base { public: virtual void foo(int) const {...} } template
Daniel Skarbek
  • 554
  • 4
  • 14
-1
votes
1 answer

C++ Class Templates Inheritance Call Constructor/Destructor

I have the following class. template class DivideConquerTask { public: DivideConquerTask() = delete; DivideConquerTask(int problemSize, int branchingSize); virtual ~DivideConquerTask(); DivideConquerTask(const DivideConquerTask& other) =…
UmaN
  • 905
  • 1
  • 15
  • 29
-2
votes
1 answer

How does std::unique_ptr set the other pointer to null when moving?

When a move happens, usually a class sets the other's pointer to null, and this is the case with std::unique_ptr. The assignment operator is templated so that you can move unique_ptrs to different types (i.e derived classes). My question is: How can…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
-2
votes
1 answer

C++20 Pass Familiar Template lambda as Class Template to Template Parameter of a Class

Consider passing a callable class template as a template parameter to some class. Three approaches as below but only functor one works. The naive template function failed because it cannot serve as a class template; However, why the C++20 familiar…
Nkk
  • 53
  • 1
  • 5
-2
votes
1 answer

C++ class template as function return type

I'm working on a little project to understand how C++ templates work. Basically, I have something like: class Base{ public: MyOperation operate(Base x){ return MyOperation(x); } //error here }; //... template class…
1 2 3
16
17