All Questions
Tagged with polymorphism c++11
236
questions
1
vote
1
answer
44
views
Polymorphic return type for child classes
I want to make an abstract class with a pure virtual function process.
process should return a variable of type Result:
class Base {
public:
class Result {
public:
int a = 1;
...
0
votes
1
answer
38
views
Creating an interface class with a function that takes unknown amount of arguments in C++
I want to create an interface class "TaskInterface" to use polymorphism later on.
Implement some specific class "ConcreteTaskExecutor" with known parameters at compile time.
After ...
-1
votes
1
answer
84
views
template specialization of unique_ptr generating member function
I am trying to make comm class with template variable.
My colleague ask me to use std::unique_ptr for memory management.
But I think I failed to implement polymorphysm.
I wrote code as the following.
...
0
votes
1
answer
41
views
How to overload << operator in derived classes on c++ [duplicate]
In my example, I have two classes: Parent and Child. I'm using a vector of pointers to Parent (vector<Parent*> v;) and I'm inserting objects of both classes into v. I'm trying to print the ...
2
votes
3
answers
338
views
Can static polymorphism (templates) be used despite type erasure?
Having returned relatively recently to C++ after decades of Java, I am currently struggling with a template-based approach to data conversion for instances where type erasure has been applied. Please ...
0
votes
1
answer
110
views
Question about polymorphism and mulitipule inheritance
I hope to store the data in three different ways:
1.store to a std::string
2.write to file descriptor
3.both of the above
And I hope to use a uniform interface for these three different methods.
I ...
2
votes
3
answers
165
views
Vector of shared pointers to templated classes
I have a templated class TaskRunner that takes a polymorphic type Task and I want to create a container of shared pointers to them.
class Task {
virtual void run() = 0;
};
class LoudTask : Task {
...
0
votes
1
answer
531
views
C++11 Polymorphism : Call derived class method from base class pointer
In summary, I believe that the answer to my question is no. However, I will have hope and defer to those smarter than I.
I would like to call a class method of a derived class from the pointer to the ...
0
votes
0
answers
94
views
Polymorphism on virtual classes with bad_alloc
I am starting out with c++, out of curiosity I am trying to catch exceptions with polymorphism. I am observing diff behaviours when trying to catch an std exception like bad_alloc vs my custom ...
0
votes
0
answers
102
views
Alternatives to normal polymorphism in embedded?
I've got a problem in my project for which polymorphism with heap allocation would be perfect. Unfortunately I'm not allowed to use any heap allocation. So I went on and implemented a way to have ...
1
vote
1
answer
75
views
Undefined behavior in replacement for polymorphism with out Pointers
I've recently asked about this on this question. And I've gone with this generic approach:
#define COFFEE_GEN_GENERIC_VALUE(CLASS_TYPE) using GenericValue##CLASS_TYPE = coffee::utils::GenericValue<...
0
votes
0
answers
30
views
Get derived value type from std::future::get
I would like to return a std::future from a class method. The value type of the std::future depends on the concrete class. I wonder how I can get() the value of the std::future without knowing a ...
0
votes
2
answers
52
views
How to remember the template type of a shared_ptr after assigning nullptr
How to remember the template type of a shared_ptr after assigning nullptr?
#include <iostream>
#include <memory>
class Base
{
public:
virtual std::string toString() { return "...
1
vote
1
answer
39
views
Using 'override' keyword
My code gives the following error:
error C3668: 'B::getData': method with override specifier 'override' did not override any base class methods
#include<iostream>
#include <tuple>
using ...
0
votes
0
answers
284
views
shared pointer to a base class where child is a template class
The crux of the issue is I want to create a vector of base pointers to reference children objects. However I'm having issues accessing the methods of the children. I've seen examples of downcasting ...