Skip to main content

All Questions

Tagged with
0 votes
1 answer
63 views

C++ virtual template member function [duplicate]

#include <iostream> class Data_X { public: Data_X(int x): x(x) {} int getData() { return x; } private: int x; }; class parent { public: template <typename T> T* ...
chandu's user avatar
  • 85
-1 votes
1 answer
248 views

C++ polymorphism not working with ESP-IDF

I have an abstract class namespace AComp { class A { public: virtual void func() = 0; virtual ~A(); }; A::~A() { } } I also have an abstract sub-class which does not ...
Bill Richards's user avatar
7 votes
1 answer
186 views

Is placement new of Derived type within a vector / array of Base type legal

Is placement new of derived object within a vector / array defined to be base object legal #include <iostream> #include <memory> #include <vector> struct A { virtual ~A() { ...
Ng Yong Xiang's user avatar
2 votes
3 answers
121 views

Virtual C++ method with no polymorphism

Suppose you have this simple class hierarchy: struct base { virtual void f () const = 0; }; struct derived : public base { virtual void f () const final { ... } }; There is ...
Flupke's user avatar
  • 21
0 votes
1 answer
29 views

Unable to make abstract member with a pointer to itself in the parameter

I need help. How can I get something like this to work? // main.cpp class A { public: virtual void foo(A* a) = 0; }; class B : public A { public: void foo(B* b); }; void B::foo(B* b) { /...
badusername's user avatar
2 votes
2 answers
95 views

Are there any advantages to pure virtual members (except the human error that they might prevent)?

I have a stack of classes with pure virtual members, it'll be populated by derived non-abstract classes. I'm getting the error: Error C2259 'ABC': cannot instantiate abstract class TEMP c:\...
Eris's user avatar
  • 35
-1 votes
1 answer
64 views

function call inside polymorphic call. virtual function call

The following is calling Derived::fn2() from Derived::fn1(), where as fn2() is not virtual so it should call Base class's function. Could anyone explain why? #include <iostream> using namespace ...
Sachin Palande's user avatar
2 votes
4 answers
693 views

What are the use cases for a base class pointer pointing to a derived class object

I'm a new to OOP and trying to learn C++ and I came cross polymorphism and using the virtual keyword. I just don't understand why we might need to do that. I've checked this site for similar questions ...
allOverThePlace's user avatar
0 votes
2 answers
72 views

an array of non-coherent types, that have something in common (array of concepts)

I think the use case is frequent, when you have multiple templated classes that have an element (variable or fcn) in common, and you want to call the fcn for all of them in a loop-like way. Clearly, ...
Ahmed Mahrous's user avatar
1 vote
0 answers
39 views

Can you have a virtual function of type Parent class and then override it as Child type (c++)? [duplicate]

Given the following structure of a Parent class and 2 childs. class Data{ protected: int data; }; class TreeData: public Data{ // something }; class PlantData: public Data{ // something }; ...
user avatar
-1 votes
1 answer
122 views

Polymorphism without implementing all virtual methods

Is NOT implementing a virtual method in all derived classes considered a bad programming practice when using polymorphism? Let's say I have an Enemy class and a couple of derived classes. All of the ...
boulder's user avatar
  • 25
3 votes
1 answer
113 views

Is overriding destructor for automatic object well defined?

I had a situation where I wanted to import a call after another call from the calling function. I decided to override a virtual destructor for the purpose: #include <iostream> struct type { ...
AnArrayOfFunctions's user avatar
0 votes
0 answers
139 views

Alternative approach to virtual template method

i am trying to solve this for some time and i hope to find some help here. I have a base class and inside the base class i need a template method. But this method can not be virtual (which i know) so ...
Miroslav Krajcir's user avatar
0 votes
1 answer
84 views

About virtual functions

I have the following code snippet: #include <iostream> #include <typeinfo> using namespace std; class A{ public: int x; A(int i = 0): x(i) {} A minus(){ return 1 - x; ...
user avatar
0 votes
1 answer
75 views

Does a virtual in a method of a c++ class trickle down to it's children [duplicate]

Why will the method of the subclass on the bottom of the tree be executed in this example? I thought that the virtual only means that if I execute the method via a pointer of the class, but that one ...
Paulemeister's user avatar

15 30 50 per page
1
2 3 4 5
16