Questions tagged [derived]
429 questions
-2
votes
1 answer
Program crashes with Vector of Derived Classes in C++
I'm on a C++ project that needs a vector of Derived classes, to go over it and call a method from the base class. For that, I did:
--Edit:
class BaseClass {
private:
float attribute1;
float attribute2;
public:
…
-2
votes
1 answer
Calling derived class overriden function from parent. C++
I have a parent class P, derived class D, and function show() in both of them. Also, i have an array of P objects, and in that array i am assigning objects derived from P, like D. And i'm calling show() function from array. But it seems that it…

hakeris1010
- 285
- 1
- 5
- 12
-2
votes
5 answers
Derived Class (Pure virtual C++)
I have problem using class base with pure virtual method.
The method should be virtual.
I get this error:
Error: object of abstract class type "Membro" is not allowed: function "Membro::mensalidade" is a pure virtual function
Anyone can…

Mister Jonh
- 31
- 8
-2
votes
4 answers
How to return the derived type from base method
For better understanding, here is what I would like to do:
Dog dog = Animal.Color("Red").Paw(4);
Bird bird = Animal.Color("Blue").Wing(1);
With the below code I could do the following:
Dog dog = Animal.Paw(4).Color("Red");
Bird bird =…

albertobrendo
- 3
- 3
-2
votes
1 answer
C++ Is there any way of storing a set of derived classes in one vector of the base class and still access their members?
Let's say I have a base class Base:
class Base
{
}
And a derived classes Derived1
class Derived1: Base
{
int a;
}
Now I have a vector:
std::vector vec;
And let's say that I have appended this with a pointer to an instance of the derived…
-3
votes
1 answer
Why am i getting this error? "Child undeclared?
I'm writing some code to show inheritance.
In doing so, i want to illustrate it by having a base class that contains a vector of pointers that can hold object pointers of the derived class.
I'm getting this error that the "Child class is undeclared"…

Arthur Imona
- 1
- 1
-3
votes
1 answer
Vector of various derived class
I still don't know how show derived class's element value from vector of pointers to base class.
#include
#include
#include
#include
using namespace std;
class bazowa;
class graf{
public:
…

user3666350
- 1
- 1
-4
votes
1 answer
How to properly desructure a derived class object when derived class pointer is assigned to base class pointer?
Is it possible to delete derived class object in proper way when derived class pointer was assigned to base class pointer? Lets consider following situation:
#include
#include
#include

Jankovsky222
- 3
- 2
-5
votes
2 answers
access protected variable in derived class c++
I have a mother class and a derived daughter class. I am trying to access the protected variable 'familystuff' in the derived class. Both ways that I am trying to access it aren't working. When I compile and run it, I get the following output:
5 3…

Anja
- 5
- 4