Questions tagged [object-slicing]

Object slicing refers to assignment by value of a sub-class instance to a super-class instance,thereby losing part of the information i.e. the sub-class specific data members are ignored.

220 questions
0
votes
2 answers

How to implement the lazy slicing of a class instance?

I am building a class which has underpinning it a list of ints, its __getitem__ method is then a reasonably computationally involved function outputting a list of potentially large size. Here is the code: Class A(list): def __init__(self, n): …
0
votes
2 answers

how to get a value by slicing a dataframe by giving three column names?

Hey stack family need some help in getting a value from a pandas dataframe but got stuck up here any help would be appreciated. I want to get a value from this ohlc dataframe. brick_counts time_id efi 1 1 1000 2 1…
0
votes
1 answer

c++ Call subclass method in vector of base class type

I have the abstract class Currency and several subclasses like FiatMoney or Crypto. I want to store all of objects of subclasses in one vector and in the same time have access to methods, which are only in those subclasses. My Currency.h file looks…
0
votes
4 answers

Unhandled Exception due to Class slicing

I'm getting an unhandled exception reading location 0x00000008 (reading NULL value) on the noted line below, relevant methods leading up to the error are included (continued below examples): Event Methods: Event::Event(Event::EVENTTYPE type) :…
Casey
  • 10,297
  • 11
  • 59
  • 88
0
votes
1 answer

How to disable slicing in C++?

Could slicing be disabled in C++ using any environment variable or any cflags options? Is any way to disable it by default?
0
votes
1 answer

Can't avoid object slicing in c++

I want to construct a std::vector containing objects derived from the Base class. I know that I can't directly push the whole object into the vector (cause of object slicing) so I use smart pointers. However, it still doesn't work. What am I doing…
0
votes
1 answer

Access subclass data member from superclass array initialized using subclass objects

A minimal reproducible example: #include class Super { private: int data1; public: virtual int getData1(){return data1;} }; class Sub1:public Super { private: static const int data1 = 1; } sub1; class…
Kitswas
  • 1,134
  • 1
  • 13
  • 30
0
votes
1 answer

Cast to reference to base class with no additional data members?

Is it safe to static_cast a concrete base class object, to a reference to a derived concrete class object when the derived class has no additional data members? Here is a simple example for illustration: #include struct Foo :…
user2023370
  • 10,488
  • 6
  • 50
  • 83
0
votes
2 answers

How to remove unnecessary items from an JSON with JQ?

I need from this: (example) { "jobs": [ {}, {} ], "services": { "service-1": { "version": "master" }, "service-2": { "foo": true, "version": "master" }, "service-3": { "bar": "baz" …
Tw1ce
  • 3
  • 1
0
votes
1 answer

Select specific substing - dynamic indexing

I have several .csv files with 2 slightly different formats. Format 1: X-XXX_2020-11-05_13-54-55-555__XX.csv Format 2: X-XXX_2020-11-05_13-54-55-555__XXX.csv I need to extract dametime field to add it to pandas dataframe. Normally I would just…
iMS44
  • 113
  • 1
  • 7
0
votes
1 answer

Getting "IndexError: iloc cannot enlarge its target object" while trying to update a cell in a dataframe

I am trying to calculate the running total and interest accrued for an account over a period of time. Running total is the sum of free cash on a day plus the interest accrued on the previous day I am trying to update the columns running total…
0
votes
0 answers

Question on the output of a tricky C++ code about inheritance

I have the following piece of C++ code: #include using namespace std; class X{ public: int i; }; class Y: public X{ public: int i; }; int main() { X ob1; X ob2; Y ob3; ob1.i = 1; …
Mohammad
  • 145
  • 8
0
votes
1 answer

Why does returning a virtual class *by value* in C++ alter the v-table?

In the following code I return a derived class CDerived by-value from a function returning its base class, CBase. For example purposes, CDerived contains a _number field, and I understand that this is "sliced" off during its conversion to the…
c z
  • 7,726
  • 3
  • 46
  • 59
0
votes
2 answers

C++ Adding objects of child classes to a vector of a parent class

I have the following class hierarchy: Crocodile Class extends from Oviparous which extends from Animal I need to store objects of type Crocodile, Goose, Pelican, Bat, Whale and SeaLion inside a vector, so: 1- I create the global…
Pedro
  • 3
  • 1
0
votes
0 answers

Vector of different objects but same parent

I want to have a vector with objects "Rectangle" and "Triangle". I want to run a function from specific index of vector. Why it calls function from parent class? Code will explain my problem better than my description :) #include #include…
LuQ232
  • 25
  • 1
  • 6