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.
Questions tagged [object-slicing]
220 questions
0
votes
2 answers
How does C++ object slicing work internally?
How does object slicing work in c++?
Could somebody please help me understand how object slicing works under the hood. To be specific, I have class Class3 which is inheriting classes Class1 and Class2 publicly like below
class Class1
{
int a,…

Pendyala
- 585
- 1
- 6
- 17
0
votes
1 answer
Python | Pandas DataFrame: Advanced Slicing/GroupBy
I have been struggling with a pandas quest for a while now and maybe someone can shed some new light into this problem :)
Consider de following pandas dataframe, df:
Year Month Task TaskID TaskClass TaskClassID SomeValue
2019 11 A 1 X …

Nuno Heli Beires
- 3
- 3
0
votes
2 answers
Python 3.X Pandas - ValueError: Must pass DataFrame with boolean values only
I have multiple pandas df that I'm trying to slice every column after a certain column (Target Col). The problem is Target Col will have a different index number each time I try to slice it. The Pandas dfs would look like…

Tfmgvi_971
- 81
- 7
0
votes
1 answer
Prevent slicing while passing by value an object (inheritance)
From what I've understood a Copy Constructer is called when an object is passed by value in a method.
So if I implement my own Copy Constructer, is there a way to avoid slicing when I pass an object by value in a method?
Example :
// in headers…

CSstudZ
- 101
- 10
0
votes
1 answer
Using iterator for slicing an array
I was looking at this python code that I need some explanation with:
arr = [0, 0, 0, 0, 1, 2, 3, 4,5]
arr = arr[next((i for i, x in enumerate(arr) if x != 0), len(arr)):]
This code would remove the leading zeroes from the array, I am trying to…

Mr Matrix
- 1,128
- 2
- 14
- 28
0
votes
1 answer
recursively extract each individual list from nested list python
not a python expert. I have a nested list like
result=[["a","b","c"],["d","e","f"],["g","h","i"], ...]
I would like to obtain separated lists for each sub list:
sublist1=["a","b","c"]
sublist2=["d","e","f"]
sublist3=["g","h","i"]
...
I know the…

Alessio Delpero
- 1
- 1
0
votes
3 answers
How to slice arrays in a for loop with the slicing indices variable
I want to slice an array of 64 items in eight parts and for that used the following method but it displayed a syntax error
for i in range(8):
s = slice(8i,(8i+7))
inparr = cornersort[s]
and
for i in range(8):
inparr =…

Amol Shah
- 15
- 4
0
votes
2 answers
The issues when avoiding object slicing using CRTP
I'd like to avoid object slicing by using dynamic_cast. I'm trying to use CRTP to avoid writing assignment operator for every derived class. The base class is "Shape" and there are several derived classes("Circle" is an example). The purpose is to…

Ben
- 1
- 1
0
votes
2 answers
Numpy slicing python 3
I have 4 arrays. Array X: is 2D array that contain examples (each has 3 features):
X = array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18], [19, 20, 21]])
Array Y contains labels for examples in Array X:
Y = array([11,…

sareem
- 429
- 1
- 8
- 23
0
votes
2 answers
How to combine slicing, templates and non derived classes?
I would like to have a container that can ingest an object, and store different parts of it into different internal containers.
Something like this:
// Pseudo-code
template
class Container {
std::vector…

Pietro
- 12,086
- 26
- 100
- 193
0
votes
1 answer
Assigning a a derived object to a baseclass pointer inside a function
I have a base class,
struct MsgFormat {
MsgFormat();
virtual ~MsgFormat();
const std::string rootNode;
};
and a derived class,
class ServiceMsg : public MsgFormat {
public:
explicit ServiceMsg(std::string A, std::string…

Duck Dodgers
- 3,409
- 8
- 29
- 43
0
votes
1 answer
Slicing pandas raw dataframe (prior to re-organizing the data)
This is my very first post but I'll do my best to make it relevant.
I have a dataframe of stock prices freshly imported with the DataReader, from Morningstar. It looks like this :
print df.head()
Close High Low Open …

citizen007
- 11
- 2
0
votes
1 answer
Pandas dataframe slicing problems in combination with pyplot
I have problems with using pandas for pyplot.
On the one hand the scale is wrong, since the value 10 on the y axis shows before 1.
On the other hand I get the error message:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
When using…

ta8
- 313
- 3
- 12
0
votes
1 answer
How do I make sure I get the derived class method called?
It's been a while since I did much with c++. I am trying to implement an the observable pattern, by passing in derived classes of an Observer class and storing them in a vector. I know I am passing in a derived class object, because the…

nPn
- 16,254
- 9
- 35
- 58
0
votes
1 answer
Is boost graph slicing my shared_ptr
I'm using an implementation of a boost graph with a boost::shared_ptr as an edge attribute. I have two class Obj and Obj2 such that:
class Obj{
public:
Obj(){};
virtual func(){std::cout << "Obj func " << std::endl};
};
class Obj2:…

Malcolm
- 662
- 7
- 29