Questions tagged [template-classes]

184 questions
0
votes
1 answer

C++ how to define the operator [] to write and read an item of the circular buffer

I have created a template class that implement a circular buffer. The buffer is formed of items that have a value of type T. I want to define the operator[ ] to write and read an element of the buffer. Even when I try to read an element already…
0
votes
2 answers

How to understand `std::make_shared("foo")`?
What does std::make_shared("foo") do? std::shared_ptr p1 = std::make_shared("foo"); I know that std::make_shared is template class and I could understand Object("foo") is a temporary object indeed. But I could not…
user13575850
0
votes
0 answers

C2672 and C2893 when Initializing Template Class Multidimentional Container

So I was writing a an object container for my template class and I keep getting C2672 and C2893 errors on my VS2019. The implemetation are as follows: template class matrixobjectprofile : public…
0
votes
2 answers

Template Classes and Functions in C++

I have a question that confuses me. I know what is template and aim of it but I have some blank points on usage. I have a Template class like that: template class SSorting { public: int seqSearch(const elemType list[], int length,…
0
votes
1 answer

Class does not name a data type?

I don't know what I did, because it was working fine (i.e. had different errors) and then suddenly my entire class just didn't exist or something because now all my function declarations and definitions just aren't happening. I don't know what's…
0
votes
1 answer

C++ vector of pointers to abstract template singleton class?

I wouldn't be shocked if this is just a mess and there's a way better way of doing it, but here's what I'm working with. I have a base class Foo, and all of the derived classes are singletons. Rather that write instance functions for each of the…
0
votes
0 answers

How to fix problems with vector and T*

I'm having a task, where I have to make a C++ implementation of a Java style ArrayList. But in a couple of areas I'm having some trouble. The declaration of the .h and the main.cpp cannot be changed. I have a template template class…
0
votes
2 answers

Template class member vs. non-member template function ambiguity

I'm developing a header-only library for automatic/algorithmic differentiation. The goal is to be able to simply change the type of the variables being fed to a function and calculate first and second derivatives. For this, I've created a template…
0
votes
0 answers

Array-like functionality with r-values

I've been writing a simple class cFlags, which is meant for storing boolean flags in single variables, as opposed to creating multiple bools (all of which take one byte of memory). Everything is working well, but I've come across this problem while…
Randoragon
  • 98
  • 1
  • 5
0
votes
1 answer

c++ array of templated abstract-base-class without breaking strict-aliasing rule

What is the best way to create an array of objects derived from an abstract template base class without violating the strict-aliasing rule. Each derived object will define the template arguments of the base class differently but only through the…
0
votes
0 answers

Base Class Pointer pointing to a Derived Class Object which is a template variable in another class

Sorry if the title is not clear.But, I'll try to explain the problem clearly. I am working on a c++ and QT using MVC for the application architecture: - Some description for application structure: Model Section (designed using polymorphism…
Samir N Ahmad
  • 575
  • 6
  • 16
0
votes
1 answer

Simpler Method for Getting the Base Class

OK so I was cooking up an answer here which has more detail (and a better alternative.) But I realized I'd made a couple template functions which had a lot of redudancy. Given: template struct Parent {}; struct Child : Parent
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
2 answers

C++ Using Abstract Classes in Template Classes

Suppose I have a template class such as: template class myTemplate and I had an abstract base class: class myDataType and various derived classes class subDataType1 : public myDataType class subDataType2 : public myDataType …
Chris Mauer
  • 176
  • 1
  • 8
0
votes
1 answer

Errors trying to overload template class friend << operator

Trying to code a better version of array type i have run into an issue. For some reason the declaration doesnt work. It throws at me bunch of weird errors. Tried looking up the issue but havent found anything so far. Here is the code: Template…
0
votes
1 answer

Why do I have an undefined reference to friend function?

In my current programming course we are writing a program to create a randomly filled array of any size. The class that contains the array must be templatized so that the array can be filled with values of int OR values of char. At this point, all…
Dane Wind
  • 21
  • 1
  • 5