Questions tagged [template-classes]

184 questions
0
votes
2 answers

Partial specialization tempate c++

I was exploring the JUCE framework and find this interesting code, namespace SampleTypeHelpers // Internal classes needed for handling sample type classes { template ::value> struct ElementType …
cedrata
  • 29
  • 7
0
votes
0 answers

I am attempting to create a Hash Table that stores values using an array

I am having trouble defining and creating said array, however. template class HashTable { public: HashTable(int intTableSize); HashTable(const HashTable& other); HashTable& operator=(const…
0
votes
1 answer

Template class initialization in main

class Q { Q(const Q &obj) {} // copy constructor Q& operator= (const Q& a){} // equal op overload } template class B{ public : T x; B(T t) { // x = t; } } int main() { Q a(2); a.init(1,0); a.init(2,1); …
0
votes
1 answer

C++ parse errors when using template class

I have a school assignment where I have to code a template class that would store the minimum of a list of ints. When running it, I get parse errors but I don't understand why. Could someone explain why I'm getting these errors? ListMin.hpp template…
0
votes
1 answer

Use class name as argument to template class based class member?

template < class _T > class CList { private: class CNode { public: CNode * m_prev; CNode * m_next; _T m_data; }; // CNode private: CNode m_head; …
Razzupaltuff
  • 2,250
  • 2
  • 21
  • 37
0
votes
1 answer

Splitting template class definitions and declarations fails for nested templates

I know what I want, but I don't know how to tell the compiler what I want. I have split declarations and method definitions in .h and .cpp file, but the .cpp file gets included in the header, so all I did was separate declarations and…
Razzupaltuff
  • 2,250
  • 2
  • 21
  • 37
0
votes
0 answers

class template error C2510: 'T': left of '::' must be a class/struct/union

Hello I'm currently analyzing a source code below which works well in Linux (MinGW) but doesn't work in MSVC, visual studio in Windows. This code is following C++ 03 rule, not C++ 11. template class CTestClass { public: static const…
0
votes
1 answer

How can I prevent template type expansion in C++?

I wrote the following classes which uses member pointer functions: #include #include template class PrimitiveAccessor { public : PrimitiveAccessor( JNIEnv* env, const char name[], const char…
JJB
  • 202
  • 4
  • 11
0
votes
1 answer

How to define a templated method of a class template outside of class body

I would like to use a templated method within a class template. I mean an additional "templatification" of the method. The following code snippet should explain what I want to achieve: #include using namespace std; // a class with a…
Andy
  • 363
  • 2
  • 8
0
votes
0 answers

How should i store some different class objects in a template class?

So, I have to create a template class that will store objects of another class, like in a vector or a list. I decided to write a simple example, like an atlas for some animals. Until now I got this, but I can not instantiate my vector with animals…
0
votes
0 answers

C++ Template class constructor calling destructor of member variable

I have a template class that holds a pair of type T with a single constructor that accepts two parameters of type T. template class Foo { T first; T second; public: Foo(T first, T second) { if (first < second) { …
littlebig
  • 23
  • 4
0
votes
0 answers

How to do multiple inheritance correctly in C++ using template classes?

I have this derived class: class Chart : public AsposeObjectWrapper, public Shape, public Php::Base { public: Chart(System::SharedPtr shape) : AsposeObjectWrapper(shape), Shape(shape) {}; } And…
user2297996
  • 1,382
  • 3
  • 18
  • 28
0
votes
0 answers

C++ derived class member is ambiguous

I have 3 classes, A, B, C. A and B both have a protected member, let's call it x. It's a pointer. C inherits from both A and B. Question: Does C have its own copy of x now? If not, what does x mean now, B::x or A::x? How can C access its own x? Btw,…
user2297996
  • 1,382
  • 3
  • 18
  • 28
0
votes
1 answer

Template Stack Class with Data types of Linkedlist gives error of Cannot Access Memory at Address c++

Here's my custom template stack class #ifndef INC_20F_FLT_PLN_DSSTACK_H #define INC_20F_FLT_PLN_DSSTACK_H #include template class DSStack { T* data; int top; int capacity; public: DSStack()=default; …
0
votes
0 answers

template class default template arguments vs default function arguments

AFAIK a template class or function can take default template arguments so I have this example for practice sake I am simulating an adapter class Array: template class Array { public: Array(T const& = T()); …
Maestro
  • 2,512
  • 9
  • 24