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
-1
votes
1 answer

Python: Two objects seem to be referencing the same variable even though I do not have any explicit connection between them

I am trying to change an octet based on the mask I have. Lets say I have IP: 194.216.35.54 and mask- 27, I need to change the 4th octet (3 when counted from 0). I am trying to change the values in the work_octets variable. But, somehow, the values…
vamsi465
  • 15
  • 1
  • 7
-1
votes
1 answer

C++ example when catching exception by value is bad

I know that when catching an exception by value, copy constructor is called, but is there anything bad when catching by value or not by reference and can you give a specific example when the bad thing happens if catching by value? (I mean except the…
Andrey Rubliov
  • 1,359
  • 2
  • 17
  • 24
-1
votes
3 answers

Is the reason fot the error object slicing?

g++ -std=gnu++0x main.cpp In file included from main.cpp:6:0: CustArray.h: In constructor 'CustArray::CustArray()': CustArray.h:26:32: error: 'class Info' has no member named 'someInfo' make: *** [all] Error 1 /* * Info.h * */ #ifndef…
user383352
  • 5,033
  • 4
  • 25
  • 20
-1
votes
1 answer

Does slicing occur with unique_ptr?

I have a pointer which sliced, but I don't exactly know where and why. There are two lines of code which I think could lead to splicing: The creation of a unique pointer: map.insert(make_pair("ChildA", unique_ptr(new ChildA()))); and the…
Yaxlat
  • 665
  • 1
  • 10
  • 25
-2
votes
1 answer

How to hide param type of template base class

Not sure if this is even possible but here goes... I'm trying to hide the param of a template base class by doing the following: Expose a common interface Implement template base class that implements the common interface Implement several concrete…
TV1989
  • 39
  • 6
-2
votes
1 answer

Using lots of static casting for my array of base class objects - is this ok?

Is a lot of static casting a bad idea ? Is there a way to avoid static casting when using containers whose element type is a base class of some subclass hierarchy? Example: The case of using std::vector to store game objects. These…
-2
votes
1 answer

Use of References or Pointers in Interfaces in C++

I am writing a library in C++, and was wondering about the use of references and/or pointers in place of the interfaces (i.e., use of (abstract) base classes as a placeholder for derived classes). The question is, which one of the two should I go…
Arda Aytekin
  • 1,231
  • 14
  • 24
-3
votes
2 answers

how to over come the issue of object slicing in c++

How should I get rid of the problem with object slicing in c++. In my application if the derived class has some dynamically allocated pointer and derived class object is assigned to base class object, the behavior is memory corruption!
srinuvenu
  • 475
  • 1
  • 5
  • 11
-3
votes
1 answer

Best way to pass multiple child classes in c++

Lets assume we have a base class Base class Base{ virtual double GetNumber(); } and multiple child classes (let's call them 'A', 'B' and 'C') that look like class A : public Base{ double GetNumber(){return 1;}; } Now I do have another class which…
Django
  • 5
  • 4
-3
votes
3 answers

Force a derived-class object to use its own function, not the base-class one

I have some doubts about subclasses in C++. I have this code: class BaseClass() { BaseClass(); void doSomething(); } class SubClass : public BaseClass { SubClass(); void doSomething(); } When I declare a BaseClass object that could…
JotaEle
  • 154
  • 8
1 2 3
14
15