Questions tagged [derived-class]
In Object Oriented languages, derived class can inherit properties and/or member functions from a base class, also called super class. cf inheritance and polymorphism.
1,192
questions
0
votes
1
answer
31
views
How do I extend or derive from the RibbonToggleButton created by the Microsoft RibbonFactory?
How do I extend/derive from RibbonToggleButton in this scenario?
I have a Microsoft Word VSTO add-in. My goal is to create a "custom" class MyRibbonToggleButton that extends or derives from ...
1
vote
1
answer
83
views
Passing unique_ptr with derived class causes SEGFAULT
could someone explain to me why executing function foo() here causes SEGFAULT? When I change the unique_ptr object in D class to contain B class object instead of A, everything works ok.
class A
{
...
-1
votes
1
answer
38
views
Including base class variables in the initializer list in the derived class
My project is to create a dive logbook.
There is the DiveInfo base class and Equipment derived class.
The equipment may change from dive to dive, so obviously it needs to get the variables for ...
1
vote
1
answer
54
views
Why does a derived class from CRTP template not initialise the static variables?
So I'm trying to create a factory based on CRTP. For simplicity, I will just include whatever is relevant here. I got two questions which might be irrelevant to each other, but was stuck trying to ...
0
votes
0
answers
29
views
How to find all derived classes that are not abstract?
I'd like to find a way to filter out abstract classes so that I don't have to manually sift through sometimes 20 classes to find the few that are instantiable, if any at all.
I have gone to the maui ....
1
vote
1
answer
63
views
Initialize base class member in derived constructor if base is inherited via template
Given I know that a certain member a exists in my base class, how can I refer to it using my template-derived class? Even if I fully qualify a, it doesn't work:
Demo
#include <iostream>
#include ...
0
votes
3
answers
84
views
How can I initialize a derived class using its attributes and the base class constructor?
Starting from a base class, I want to create some derived classes, which differs from one another for the value of a number of data members. These different attributes are used in the BaseClass ...
0
votes
1
answer
48
views
How can I add new attributes to a pandas.DataFrame derived class?
I want to create a class derived from pandas.DataFrame with a slightly different __init__(). I'll store some additional data in new attributes and finally call DataFrame.__init__().
from pandas import ...
0
votes
0
answers
31
views
Is it possible to deserialize JSON from different web sources with C# derived classes?
Intent: Receive data in json format, from diferent web sources, returning diferent list of data, and deserializing it.
Almost sure this is a newbie C# question :(
No experience with derived classes ......
2
votes
3
answers
127
views
Why do I get a wrong pointer to a base class with a virtual constructor on C++?
I want to derive a structure from the plain old trivial C structure ::sockaddr_storage so I can extend it with methods to handle its own data. I can type cast the derived structure as usual to get ...
1
vote
1
answer
47
views
Making a class template that is dependent on another template
So I have a set of classes that are all derived from a base class RigidBody (NOTE: In the following code Tp is used to specify a precision type (e.g. float), while Tc is ued to a specify a color type (...
0
votes
3
answers
71
views
Is a pointer to map of base classes valid?
I would like to iterate some code over a few maps that have different value types, but which are all derived from a base class, which I can guarantee is the first inherited class, and the classes are ...
0
votes
2
answers
110
views
DnD Dice Roll Simulation
I am Trying to make a simulated dice rolling game for my friends. I want to utilize two classes Dice and a child class VarDice which will let user choose how many sides. However, I am struggling to ...
-2
votes
2
answers
126
views
How do I overload a function with a parameter with a type that is a child class of the base parameter?
If I have a base abstract class with a function that takes it's own class as a parameter:
class Component abstract
{
public:
virtual bool Method(Component& other) = 0;
};
And I have a child ...
0
votes
1
answer
50
views
Is there a way to make class name as a variable? ... parent_class *p_derived = new classnamehere();
I'm trying to follow DRY and I want to put initialization of a new class in function but there is one problem.
My class is a parent class and I'm initializating new derived class in this function.
...
0
votes
0
answers
76
views
How to call base class function from vector of derived class with templates without virtual functions in base class?
#include <iostream>
#include <vector>
#include <memory>
#include <string>
class IModule {};
template<typename T>
class Base : public IModule{
public:
T BaseT;
...
4
votes
3
answers
107
views
What will happen if dynamic_cast<void*> casts an object with underlying non-most-derived class?
We know that dynamic_cast<void*> will cast a pointer to the pointer to the most derived object; but what if the underlying object is not the most derived? For example:
class BaseClass { public: ...
0
votes
2
answers
68
views
C# override an abstract method with base classes with a method using derived classes
Can't seem to find a solution, and don't see why this is not possible:
(this first line of code does not seem to want to format properly on my browser)
namespace Definitions
{
public interface ...
0
votes
1
answer
46
views
Accessing property of derived type in a class derived from a generic class [duplicate]
I'm still new to C# and cannot wrap my head around this issue.
I have a two classes deriving from a generic class with T deriving from BackgroundWorker (see below). How can I have a field in another ...
-1
votes
1
answer
63
views
C++ Base class member creation via derived class [closed]
I'm having difficulties understanding the following code:
class Base{
Base(){/* do stuff */};
};
class Deriv: public Base{
Deriv(){/* do stuff */};
};
// I have a problem understanding the ...
0
votes
1
answer
51
views
How to implement derived classes for interfaces?
I have examined a few posts but nothing seemed to cover my question.
I have an interface full of pure virtuals.
I have an implementation class of the interface which is made up from various public ...
0
votes
0
answers
205
views
Issue with ros NodeHandle.subscribe with a class method
I am using ros melodic on Ubuntu18.04 and C++14 and am trying to subscribe to a topic using a callback function in a Derived class. I know this is possible as a base class as seen in the 2.3.2 Class ...
0
votes
0
answers
73
views
Understanding how to work with derived c++ classes in Openacc?
I'm trying to implement some plasma physics codes on GPUs. However, I have a problem of the following type:
I have two classes: base and derived. The derived class contains an additional pointer that ...
0
votes
2
answers
49
views
Pointers to an anonymous and named Inner Derived Class of a Base::Inner Class have different behaviors
I have a Base Class with an Inner Class with two pointers to the Inner Class and one Inner Class data member.
I next define a Derived Class with two Inner Derived Classes, one anonymous, one named.
...
2
votes
1
answer
54
views
Get properties from object
I have a method that must run different ways, depending on the type of the object received. But, I don't know how to access the properties of the object.
I'm also not sure that it is the correct way ...
0
votes
2
answers
229
views
Deserializing JSON with List of abstract class
In my project i receive a JSON which represents a Configuration for an device. Each device has one or more Interfaces that it can be connected with. In the property "SupportedInterfaces" i ...
0
votes
0
answers
18
views
Derived class cannot recognize inner class of base class [duplicate]
Can someone here tell me how to get the derived class method below to recognize the inner class Option from the base class?
template <typename T>
class Menu {
protected:
class Option { };
...
0
votes
0
answers
16
views
Undefined Reference Error when using new identifier for a derived class in a new cpp file, when previous identifier was T [duplicate]
I was given 4 files, ArrayBag.cpp/.hpp and Animal.cpp/.hpp. The goal is to create a new class, ZooRecord and implement it in respective cpp and hpp files. This class inherits from ArrayBag and stores ...
-2
votes
1
answer
108
views
Why can you return Task<TResult> when Task is expected?
As I was messing with tasks, I made a private static async method that returns a random number after a delay. I had also made a public static method that calls the private static async method, but I ...
0
votes
2
answers
74
views
C++ Functions Select Behavior Based on Passed Parameter Derived Class?
What I'm trying to do is to have a base class that has a primary functionality, as well as multiple derived classes that have various other additional functions/variables. The main functionality of ...
0
votes
1
answer
49
views
Why can i only access protected members of a class inside a method of a child(derived class)?
#include <iostream>
using namespace std;
class parent
{
protected:
int main = 0;
};
class subclass : public parent
{
cout << main; //error
void function() //ok
{
...
-1
votes
1
answer
44
views
Multi-type container C++. Casting to derived template class
I am trying to implement a multi-type container in C++ without using std::any, std::variant, boost::any, etc. The add() function adds new objects (int, string, or other Structures) by wrapping them in ...
-2
votes
2
answers
469
views
I'm not sure what I'm doing wrong on this program
Define a Course base class with attributes number and title. Define a print_info() method that displays the course number and title.
Also define a derived class OfferedCourse with the additional ...
0
votes
0
answers
30
views
super not working as I expected? (calling derived method instead of base method)
Let's say we have the following code:
public class A {
void someMethod() {
System.out.println("Some method from A");
}
void someOtherMethod() {
System.out.println(...
-3
votes
1
answer
85
views
What does this program do, and how does it do that? [duplicate]
I am having trouble figuring out why this program works. I wrote it based on my notes (OOPP and classes) but I do not understand how exactly it works? I would appreciate any help!
Here is the code:
#...
1
vote
1
answer
83
views
How can I inherit a template class in its specilization class?
If I have a class like: Vector<T> (a template class), and now I want to specialize it: Vector<int>. How can I inherit from Vector<T>?
My code is:
template<typename T> class ...
1
vote
1
answer
278
views
Why is `this` undefined in a constructor defined Proxy method for a derived class?
I attempting to overwrite/proxy a function from a library class. I've done this by extending the class and defining a Proxy object over the method.
Alas, like in this question, the this object in the ...
0
votes
1
answer
47
views
Array of derived objects cannot use the derived methods
Following up on this question C++ inheritence and array I have a question about derived classes and their methods.
Currently I have this base class
class FunctionBlock
{
public:
uint8_t IN1 : 1 ;
...
0
votes
0
answers
103
views
Instantiate object as parent or child class without knowing which until constructor (PHP)
What's the best way to instantiate an object as either an instance of a parent class or an instance of a derived class, if you don't know which one to instantiate it as until after you start the ...
0
votes
1
answer
34
views
how to derive a class (from e.g. Eigen::VectorXf) with (only) an extra static method while retaining all the base constructors?
Let's say I need to attach some 'type id' to my Eigen::VectorXf vectors.
So far I have something like this (simplified for brevity):
struct MyVector123
{
Eigen::VectorXf vec;
static int id() {...
1
vote
2
answers
255
views
Base class default constructor in derived class constructor initializer list
I have seen a lot of times people adding the default constructor of base class in the derived class constructor initializer list like so
DerivedClass::DerivedClass(int x) : BaseClass(), member_derived(...
1
vote
2
answers
164
views
shared_ptr to derived class from a specific base class
I feel like this is a pretty basic C++ question. I am trying to make a class which contains a member variable which is a shared_ptr to any class which is derived from a specific interface, but does ...
1
vote
1
answer
61
views
Use non virtual methods in derived class C++ [closed]
I have an abstract Class Person and 2 derived Classes Customer and Employee. I store them in a list personList with the type Person* (list<Person*> personList). Now Customer has its own method ...
1
vote
0
answers
89
views
Force derived class to call base class function. How do I force the base class function to use virtual base class version of functions?
Suppose I have the following code
class A{
public:
void f1()
{
/*
* Other functions that happen here.
* These calls needs to be made at A's f1() function
* And ...
0
votes
2
answers
773
views
How do I access private member variables with public member functions (derived class)?
I need to get access of the base class private member variables using public member functions from the derived class. That means, I can call it anytime in a public member function from the derived ...
0
votes
1
answer
55
views
How to make two classes with different member variable type and different constructor into derived/base class or template class?
class Data
{
public:
int i;
};
auto cmp = [](const Data& d1, const Data& d2) { return d1.i > d2.i; };
class A
{
private:
queue<Data> q;
public:
A() {};
void func() {
...
0
votes
2
answers
56
views
derived class as a parameter of templated function which is specialized for its base class
class Base {};
class Derived : public Base {};
class SomeClass
{
template<typename T>
static void SetContent(T* pChild, OVariant content)
{
LOG_ASSERT(0, "All classes ...
0
votes
0
answers
48
views
C++ error: using temporary as lvalue when using member variable of container in dervied class
#include<iostream>
class acc{
public:
acc() { aa = 10;}
int aa;
};
class Derv;
class Base{
public:
Base() {}
int a;
virtual acc get_acc() {};
...
0
votes
0
answers
73
views
If I need to work before or after call virtual function, is NVI idiom always better than other interface?
From what I understand, NVI idiom grants hardened privileges to base class and places constraints on derived classes.
Because behaviors such as pre-action, post-action, when to call are implemented in ...
2
votes
3
answers
99
views
How do I properly derive from a nested struct?
I have an abstract (templated) class that I want to have its own return type InferenceData.
template <typename StateType>
class Model {
public:
struct InferenceData;
virtual ...