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

Object Slicing in c++

class Base { int iBase; public: virtual void display() { cout<<"I am a Base Class"<
vrbilgi
  • 5,703
  • 12
  • 44
  • 60
0
votes
2 answers

Min or Max of pandas data series between two rows

I have a pandas dataframe. Suppose the column names are 'A', 'B', and 'C'. How can I calculate the min and/or max of data in column 'A' inclusive of only rows m to p? Where m < p and m != 0 and p < the number of rows in the dataframe. What if I…
DeeeeRoy
  • 467
  • 2
  • 5
  • 13
0
votes
2 answers

Prevent slicing in "throw e;" when passing an unthrown exception as a parameter

If I want to provide a substituteable ErrorHandler class which can be used to provide different styles of handling (e.g. rethrow, log and rethrow, swallow, call some function, etc), then I can do something like the following: ErrorHandler.h (this is…
chrisb2244
  • 2,940
  • 22
  • 44
0
votes
0 answers

Storing an inherited class in a vector

I have a main class of an object called CEmploye and a child of this class called CTechnicien. This is the code for CEmploye #pragma once #include #include class CEmploye { public: /*Constructeurs/Destructeurs*/ CEmploye…
Kalixio
  • 1
  • 1
0
votes
2 answers

Python sum values in list of tuples up to certain values

NOTE: I edited the question! I am having trouble with iteration in Python, especially when I would like to sum up values up to a certain number. Here's more information on the problem I'm facing: I have a list of tuples that looks like this: [(1,…
djennacs
  • 107
  • 1
  • 7
0
votes
3 answers

C++ Confused by this code with polymorphism, pointers and object slicing

I'm trying to understand how polymorphism, object slicing and pointers work in this block of code. I'm working in Visual Studio. #include class Man { public: virtual void speak() { std::cout << "I'm a man." << "\n";…
0
votes
1 answer

Can we outsmart object slicing?

DISCLAIMER: Keep reading only if you want to see how it's NOT done. Apparently it's so wrong you will get eye cancer from it when you see it (I'm immune because I'm a noob :) So I was thinking about runtime polymorphism in C++ for a while and I…
0
votes
3 answers

Slicing when inserting pointer of derived class into vector of base class

My base class is called Account while the derived class Businessaccount has an additional int variable called x, as well as a getter-method (int getx()) for it. Is slicing supposed to occur in the following situation? It obviously happens in my…
zunnzunn
  • 366
  • 1
  • 5
  • 12
0
votes
0 answers

Google Mock - mocking two dependend interfaces

I have two interfaces I like to mock. Unfortunately one depends on the other and vice versa. The ICredentialProviderCredentialEvents has a methods that expect ICredentialProviderCredential as a parameter. ICredentialProviderCredential has a method…
Frank
  • 2,036
  • 1
  • 20
  • 32
0
votes
0 answers

C++ - Object Slicing Object holding vector of objects

So I am working on a project and I am currently trying to render textures. Currently RectTextures inherits from Textures. RectTextures has its own render() function because I want other types of Textures (like text) to render differently. I then…
Meuktwo
  • 1
  • 2
0
votes
2 answers

Python str slicing out of list

I would write a little function to check if a string in a list, and when yes, the string should remove out of the List. this is my code def str_clearer(L): for i in L: if i == str: L.remove(i) else: pass …
Arresh
  • 11
0
votes
1 answer

Slicing arrays based on boolean array in python

I need to slice an array of xyz coordinates based on conditions in a boolean array (where the boolean array is 1D). If my boolean array is [1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1] I need it to slice it to produce the following index…
stagermane
  • 1,003
  • 2
  • 12
  • 29
0
votes
1 answer

Python: slicing a list into a list of lists using list comprehension

I have a simple list like this: mylist=[0,1,2,3,4,5,6,7,8,9] which I want to slice creating a list of lists. The intended outcome is: sliced=[[0],[0,1],[0,1,2],[0,1,2,3],...] First attempt: sliced=[mylist[i:i+n] for i in range(0, len(mylist),…
FaCoffee
  • 7,609
  • 28
  • 99
  • 174
0
votes
2 answers

Slicing a C-array creating a C++ vector, keeping only 2 elements every 3

I have a C-array like this: int X[]={0, 1, 2, 3, 4, 5, 6, 7, 8}; I need to create two stl vectors out of this array, by means of slicing, possibly sharing the highest amount of memory and making less deep copies possible. The first vector Y must…
linello
  • 8,451
  • 18
  • 63
  • 109
0
votes
1 answer

Show user position on 2D maze - Python

I have this task where I must print a maze that also provides the user's position. However this position can be dependent on the generated position from another function. What I mean is that the position can have many different possibilites. I…
Pfraylen
  • 1
  • 1