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

Using this slice my object

I have some difficulties using this, it seems to slice my derived class. This example will help me to explain my problem. class A { A() { OtherClass(*this); } virtual doSomething() = 0; } class B : public A { B() : A()…
Nitixx
  • 48
  • 6
0
votes
2 answers

Python - Array slicing

I have an assignment from my university. They asked me to analyse a slicing operation and explain it. A = array([[1,2,3],[4,5,6],[7,8,9]]) A[0,arrange(3)<>0] A[1,arrange(3)<>1] A[2,arrange(3)<>2] The operation to analyse is the following: A[k,…
BobaJ
  • 1
0
votes
1 answer

How to solve this Object Slicing issue with GoogleMock

Below is one of the line in my method. Here i have to mock the method "findChild" and make "Chino::mock_Button" instance to be assigned to the "close_button". This is my requirement. Chino::Button* close_button =…
Bharathi
  • 337
  • 1
  • 5
  • 17
0
votes
3 answers

Function polymorphism with Reference Data Type

I have a queue that contains Objects of class Event. std::priority_queue events; But Event is just a superclass of actual events. Lets assume we have following classes: class Event{ public: void Action(){ std::cout<<"do…
0
votes
1 answer

ValueError: could not broadcast input array from shape (1,19) into shape (1,20)

I keep on getting this error when I am trying to do simple numpy array slicing. It's hard to describe this code but basically I have an image (binarised, by name and properties) and I have created a small box window (1x20), I am trying to loop…
Scott Alistair
  • 161
  • 4
  • 12
0
votes
1 answer

Object slicing when using CRTP

I am stuck with an object slicing problem when using CRTP. The following mock illustrates my problem. #include class CrtpGenr { }; template class CrtpBase : public CrtpGenr { public: static auto…
vixiv
  • 161
  • 8
0
votes
1 answer

Object Slicing : Access dervied class methods from base class object

Edit : The problem is in the GoFish.h file, in the constructor to be specific, where it is trying to instantiate the players object. The compiler throws the following error message : no member named 'noOfBooks' in 'Player' GoFish() {players…
Luv
  • 44
  • 6
0
votes
2 answers

pandas, slice multi-index df with multiple conditions

This question is a continuation of pandas re-indexing with missing dates I want to compute the sum of the values for the most recent 3 months (2015-12, 2015-11, 2015-10). If a stock doesn't have sufficient data i.e. has none,1 or 2 of the 3 months…
codingknob
  • 11,108
  • 25
  • 89
  • 126
0
votes
0 answers

Inheritance or Object Slicing?

I've read up so much on this, and can't figure out why my Player object is losing its draw function. Object class: class Object { public: Object(){} Object(Object* o){ o->draw(); } virtual void…
MPenate
  • 85
  • 1
  • 6
0
votes
0 answers

How to divide a dataset according to a value in a column?

I have a pandas data frame with a column that represents dates as: Name: ts_placed, Length: 13631, dtype: datetime64[ns] It looks like this ( it was recoded using week as time unit): 0 42 1 44 2 44 3 41 4 43 5 45 6 …
Blue Moon
  • 4,421
  • 20
  • 52
  • 91
0
votes
1 answer

Virtual method being called instead of derived method

i'm having trouble with an inherited function and i can't seem to figure out why it's behaving the way it is, and haven't been able to find an answer in other questions on SO. I'm working on a small game and the inherited function is responsible for…
0
votes
1 answer

numpy get 2d array where last dimension is indexed according to a 2d array

I did read on numpy indexing but I didn't find what I was looking for. I have a 288*384 image, where each pixel can have a labelling in [0,15]. It is stored in a 3d (288,384,16)-shaped numpy array im. With im[:,:,1], I can for example get the image…
maxbellec
  • 16,093
  • 10
  • 36
  • 43
0
votes
2 answers

Calling child method

In my C++ project I have a class called Trap. A Trap is an NPC and an NPC is an Entity. Now I want to loop through all NPC's and do stuff with them. For example, I want a Trap to update. I do that in the following way. for (vector::iterator it…
Ozitiho
  • 346
  • 2
  • 9
0
votes
2 answers

Class Slicing within Vector

I believe I have a slicing problem, and I am not sure how to fix it. I have summarized the issue from my actual program into the example below. #include #include using namespace std; class Base { public: void Use(void) { …
halexh
  • 3,021
  • 3
  • 19
  • 19
0
votes
2 answers

Why does slicing occur?

Please consider the following code: Base b; if (something) b = DerivedA(); else b = DerivedB(); It's well known that in such a case, 'slicing' occurs: In C++ we can't assign a variable of a base type an object of the derived type; the…
Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131