Questions tagged [template-classes]

184 questions
1
vote
1 answer

Access to a member data via a class template specialisation

I can not access the member data "value" defined in the template class from the specialized one. Why? Some one can help me? Thanks template class A { public: int value; A() { value = 0; } }; template <> class A
thewoz
  • 499
  • 2
  • 4
  • 23
1
vote
2 answers

Initializing a template constructor with a size_t type variable

I have a class, with a template constructor : class x { public: template x(int matrix[N][N]) { A ob(matrix); } }; in main function : int main() { size_t s; cin >> s; int m[s][s]; x ob(m);…
Code Devil
  • 17
  • 7
1
vote
2 answers

VS Code/MinGW intellisence not working for C++

I have a template class in my header file, I also need a .hpp file for the function implementation. The issue is with VS Code or MinGW. In VS Code: I installed the C/C++ extension by Microsoft Here is my c_cpp_properties.json…
1
vote
1 answer

Is it possible to store function parameters as some kind of list

I have a base class template class Base { public: Base(T foo = T()) { for(int i = 0; i < 10; i++) foos.push_back(foo); } private: std::vector foos; } and I have a derived class class Derived :…
po0l
  • 98
  • 8
1
vote
1 answer

Template specialization with another template

Say I have two template classes template < class T > class Foo { /**/ }; and template < class T > class Bar { /**/ }; how can I specialise Foo with Bar ?? what is the syntax?? is it template<> template class Foo> {…
WARhead
  • 643
  • 5
  • 17
1
vote
2 answers

Template typedef is not a class or namespace name

I'm writing a template class which should behave like a container. Inner data is a vector of smart pointers to the generic class T. Header #include #include namespace Foo { template class AstrContainer …
Patrizio Bertoni
  • 2,582
  • 31
  • 43
1
vote
2 answers

Is there a way to check what datatype a template is?

Say I have the following code: template int Hash::hf(const K& key) { if(K == typeid(string)) { return MurmurHash2(key.c_str(), key.size()); } else { …
1
vote
1 answer

How can a template class be an attribute of another template class of the same type T in c++?

I have a template class Tripla (node for a list structure) and another template class Lista. I want to make them generic so they can reused in the future, however I'm not sure how to set the data type to the Tripla objects from the class…
1
vote
2 answers

partial specialization of a static const member variable

Currently, I've implemented a template class Mat that's a wrapper around the matrix class of a third party library (T is the type of the components: double, int, etc.). Now, I wish to implement a Tensor class uses one Mat for storage and a second…
1
vote
2 answers

how to adjust a c++ code to work with template class

Following codes are part of a Red Black Tree program which has to take item as a char or int, so I decided to use a template class, however I don't know how to extend it through the complete program and the compiler sends me thousand errors: The…
Bahador
  • 75
  • 1
  • 11
1
vote
1 answer

c++ store a reference to a pure virtual class as member of class

I have a templated wrapper containing an instance of a class which inherits of a pure virtual class. My problem is how to store the data inside the wrapper. - I can't use a copy because pure virtual classes can't be instanciated (or sliced if I use…
Antoine
  • 910
  • 1
  • 9
  • 26
1
vote
0 answers

Doxygen Inheritance Diagrams: Template Classes

I currently use doxygen to create documentation for a project. Recently, a small part of this project started using template programming and the resulting inheritance diagrams created by doxygen do not really fit into the rest of the…
Gregor de Cillia
  • 7,397
  • 1
  • 26
  • 43
1
vote
2 answers

Can a class inherit from another class template concretized by itself?

I was going through some code and I found something like this: class GarbageCollectorProcess : public process::Process I was wondering if this was a valid thing to do. If yes, shouldn't this lead to some kind of a self…
ibp73
  • 650
  • 1
  • 6
  • 16
1
vote
2 answers

Can keyword "explicit" be removed from a constructor in one specific template instantiation?

I'm trying to create a template class to enforce dimensional correctness (length divided by time gives speed, and so on). The short story: "Dimensionless" is one of the possible instantiations. It would be convenient if I could allow all…
user1476176
  • 1,045
  • 1
  • 7
  • 15
1
vote
1 answer

Drawing a Template Class in UML

I have a problem drawing a template class diagram in UML. I know that in UML a template class should have a small rectangle in the up right corner of the class but the problem is how do i draw that ? Is there any special option called template…
Troller
  • 1,108
  • 8
  • 29
  • 47