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
1 answer

How to define static member variable from class template with specialization?

OK I have this code: // default implementation just uses a mutex to serialize access template struct kernport { static const bool atomic = false; // constructor kernport(T value=T()) { set(value); …
gct
  • 14,100
  • 15
  • 68
  • 107
0
votes
0 answers

std::enable_if - custom type trait that handles types and a template

I have a function template, and a class template: template T testFunction(T argOne, T argTwo) { //Implementation } template , int> = 0> class testClass { //Implementation } I want to…
0
votes
0 answers

Accessing static members of a class having Inherited Enum

I am having an error with accessing static members of the class CErrortracker(example code below). What is being tried here is to have a common Error module which has an id, error level and the error source. The error source basically will have…
Barry
  • 133
  • 1
  • 1
  • 9
0
votes
0 answers

Visual-C++ compilation failure if using a class template utilizing if constexpr statements within another class template

I wrote a matrix class template which, amongst other things, includes arithmetic operators which are specialized for certain class template parameters utilizing if constexpr statements. The use of this matrix class within another template class may…
0
votes
1 answer

How can I add data from a public method into a private member array in the same class?

I'm having trouble storing data read in from the keyboard into a private member array. When I try to simply add the data using: std::cin >> array[counter]; I get a long error: pasted here to save space I'm currently trying to find a way to store…
user10410161
0
votes
2 answers

Argument list for class template "calc" is missing

I am trying to modify the class “calc” to be more generic to accept also doubles or floats. class calc { public: int multiply(int x, int y); int add(int x, int y); }; int calc::multiply(int k1, int k2) { return k1 * k2; } int…
CrDS
  • 77
  • 3
  • 8
0
votes
1 answer

class template without public constructor as member of another class template

I have a class template Shape, which contains information about certain shapes (which can be three- or two-dimensional). I only want a few predefined shapes (cube, sphere and square) to be available. All these predefined shapes have the same…
JorenV
  • 373
  • 2
  • 10
0
votes
1 answer

Class inheritance and operator overloading

I'm learning C++ with a small project on SFML, and I wanted to extend the sf::Vector2 class, which represents a 2D math vector. The declaration of this class is available here. In particular, I wanted to add some methods to the class, for norm…
DarkChipolata
  • 925
  • 1
  • 10
  • 29
0
votes
1 answer

C++ - Printing vector elements for derived class objects

I have an abstract class named Pet and three derived classes Cat Dog Goldfish. I am trying to store them in vector and print the pets names. But I am getting some hexadecimal number. I don't know where I am doing wrong. // Here is pet.h #ifndef…
0
votes
0 answers

std::pair class template has already been declared as a non-class template

I'm trying to declare two structs with the same structure as a below. struct pair { unsigned int r1; unsigned int r2; unsigned int diff; }; struct srm { struct pair *pairs; struct pair *ordered_pairs; }; And it generate the…
Suho Cho
  • 575
  • 1
  • 7
  • 14
0
votes
1 answer

Protected destructor disables creating derived class's objects on stack?

In this webpage about Curiously Recurring Template Patten, the derived class can be instantiated on the stack (the Object Counter example, in which the base class template has a protected destructor): CRTP-wiki.. i compiled myself. template…
Leedehai
  • 3,660
  • 3
  • 21
  • 44
0
votes
0 answers

CMake Linker: Undefined reference even though library is linked

I am using CMake (CLion) for a class project. I have tried the following solutions but they did not work: 1, 2, 3. I made a HeapSort class for a class project and I need to use it to sort a vector of strings (a dictionary). I create an instance of…
0
votes
0 answers

Static member within a class template

I was coding a class template to implement a Singleton when an issue occured. While having a static pointer in a .h file, it wouldnt compile because of a linker issue (lnk 2001 and lnk 1120 on vs 15). I Simplified my code to have the more…
Arkhain
  • 21
  • 1
  • 8
0
votes
1 answer

Why this template class doesn't work properly?

#include using namespace std; template class Array{ public: Array(int sizeOfArray=1){ arr = new T[sizeOfArray]; for(int i=0;i
Andrew
  • 1
  • 4
0
votes
0 answers

Why am I having an undefined reference error using class Templates?

Both classes are in header file, that is not the problem. For some reason my program tells me that I have an undefined reference error. I am not totally sure why that might be. I have one implementation file for 2 classes. Might that be where the…
blackstreet23
  • 17
  • 1
  • 4