Questions tagged [template-classes]

184 questions
2
votes
2 answers

Reduce code duplication in class template specialization (array)

How to reduce code duplication of a class that is template specialized? I am trying to create a class (MyArray) that acts like std::vector but receives raw-pointer as parameter in some functions. Here is a simplified version of it…
javaLover
  • 6,347
  • 2
  • 22
  • 67
2
votes
2 answers

How to form a variadic template function within a non-variadic template class?

So, as I've been learning about templates in C++, I decided to come up with some unusual situations to see if I could get them to work. (No, it's not practical - just to play with the language!) I made a template class that holds a value of type T,…
2
votes
1 answer

how is template class matched

I try to understand the enable_if implementation, which is a pair of template classes. what I do not understand, why enable_if is not matched to the first one? how is this decided? #include template
pepero
  • 7,095
  • 7
  • 41
  • 72
2
votes
3 answers

Pull Apart Function Type With Specialized Function

The answer to this question picks apart a function type using a class template: template struct function_args {}; template struct function_args { using type = tuple; }; template…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
2
votes
0 answers

c++ template class member specialization and inheritance

I would like to write down a set of classes in which there are: a pure virtual class that wraps an object of any kind and the relate getter for it. one or more classes for every kind of object I need, extending the virtual one and overriding the…
ruphus
  • 163
  • 1
  • 13
2
votes
1 answer

defining numeric_limits max function for template class

I have problem with defining function max for template class. In this class we kept a numbers not as simple integers, but as vector of numbers in some numeral system. And with defining numeric_limits i need to return representation of maximal number…
Yurrili
  • 338
  • 1
  • 11
2
votes
2 answers

C++ Partial-specialization of class in source not header

Foo.h template class Foo{ public: Foo(); /*..*/ }; Foo.cpp template Foo::Foo(){/*...*/} template Foo::Foo(){/* some specialized construction */} //<- this doesn't…
shavera
  • 803
  • 1
  • 8
  • 18
2
votes
2 answers

How to make multiple template class to have the same type

There are two template class A and B. How to enforce them to be instantiated to the same type without nesting one with another? e.g. If I define the two class like the following: template class A {}; template class B {}; Then…
newbie
  • 154
  • 7
2
votes
1 answer

Link error when I put template class with non-template classes in same cpp file - C++

I have a link-time problem when I include a templated and non-templated class in the same .cpp file. I went through the C++ FAQ 35.13,35.14,35.15 and it doesn't solve the…
Charles Chow
  • 1,027
  • 12
  • 26
2
votes
1 answer

Template classes with native UML types, and OCL constraints for template classes

I have two questions concerning the same UML class diagram. The first one is about how to model template class with UML native types. The second one is about how to handle template classes in OCL constraints. Question 1: template class I would like…
Bastien Pasdeloup
  • 1,089
  • 12
  • 19
1
vote
1 answer

Passing designated initializers for a template class to a template function

My goal is to create an API interface that looks like that this: struct myAB{ int a,b; }; void function(myAB ab) {} ... function({.a = 1, .b = 3}); The above works just fine. But if I want struct AB to have a templated type, CTAD fails. template…
dada_dave
  • 493
  • 4
  • 13
1
vote
2 answers

class template of a c style string rvalue type fails to be compiled: returning array error

Consider the following template class: //Node.hh template class impNode { private: dataType _data; public: explicit impNode(const dataType &data) { std::cout << "this constructor is called!" << std::endl; }; …
Juan_David
  • 126
  • 2
  • 11
1
vote
2 answers

C++: Is there a simple way of using a namespace as template?

Is there a way to use a namespace as a template? I need to call the same function but from a different namespaces. Something like that: There are two namespaces here myNamespace1, myNamespace2 that contain a function with the same name -…
Shoam
  • 25
  • 2
1
vote
1 answer

Forward declarations don't work the same as in-place forward declarations when used in class context

I'm poking around in the myst of C++ instantiation / declaration order. Here's a fun bit I came across: This compiles : #include #include #include template struct container { // THIS COMPILES struct…
glades
  • 3,778
  • 1
  • 12
  • 34
1
vote
1 answer

How to wrap a shared pointer of a template class function in Pybind11

I want to wrap a shared pointer of a template class function in Pybind11. My class is a template queue : MyQueue.hpp template class MyQueue { public: std::queue the_queue; static…
1 2
3
12 13