“Slicing” is where you assign an object of a derived class to an instance of a base class, thereby losing part of the information – some of it is “sliced” away.
For example,
class A { int foo; }; class B : public A { int bar; };
So an object of type B
has two data members, foo
and bar
.
Then if you were to write this:
B b; A a = b;
Then the information in b
about member bar
is lost in a
.
Related Posts:
- What are the differences between a pointer variable and a reference variable in C++?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Why is “using namespace std;” considered bad practice?
- What is a lambda expression in C++11?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- What does the explicit keyword mean?
- What is a smart pointer and when should I use one?
- What does the explicit keyword mean?
- Why is enum class preferred over plain enum?
- Inheriting constructors
- What is the difference between const int*, const int * const, and int const *?
- What does T&& (double ampersand) mean in C++11?
- What is the difference between const int*, const int * const, and int const *?
- Inheriting constructors
- What is move semantics?
- Is the practice of returning a C++ reference variable evil?
- How to write C++ getters and setters
- What are the differences between struct and class in C++?
- What is std::move(), and when should it be used?
- gcc/g++: “No such file or directory”
- Resolve build errors due to circular dependency amongst classes
- cannot declare variable ‘’ to be of abstract type ‘’
- How to call a parent class function from derived class function?
- QltAW.png
- std::wstring VS std::string
- Why is inherited member not allowed?
- Class template inheritance C++
- Why should I use a pointer rather than the object itself?
- Struct inheritance in C++
- C++ calling base class constructors
- Here is some error with my .h file which show [Error] unterminated #ifndef when I include my class template in it
- What is a segmentation fault?
- Sleep for milliseconds
- C++ Cout & Cin & System “Ambiguous” [closed]
- How to read a file line by line or a whole text file at once?
- Split a string using C++11
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- How to track down a “double free or corruption” error
- The Definitive C++ Book Guide and List
- undefined reference to `WinMain@16′
- How can I clear console
- How to go from fopen to fopen_s
- How to get current time and date in C++?
- where is the official c++ documentation
- wntdll.pdb not loaded – Can’t see the exception
- Networking with C++
- Error a function-definition is not allowed here before ‘{‘ token
- invalid new-expression of abstract class type error
- How can I create objects while adding them into a vector?
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- “Symbol(s) not found for architecture x86_64” on QtCreator project
- basic_string::_M_construct null not valid after constructing subvector of strings
- Does C++ have a Garbage Collector?
- Is “argv[0] = name-of-executable” an accepted standard or just a common convention?
- How to fix ‘std::logic_error’ what(): basic_string::_M_construct null not valid error?
- What does the assignment of ~0u to a variable mean in C++?
- expected expression in C++?
- How to access the contents of a vector from a pointer to the vector in C++?
- printf with std::string?
- “Error: expression must have a pointer type” when using the “this” keyword
- General way of solving Error: Stack around the variable ‘x’ was corrupted
- error MSB3073: How do I fix this?
- timestamp of time(0) at multiple places in a C++ program
- What’s the most efficient way to erase duplicates and sort a vector?
- How can I iterate through a string and also know the index (current position)?
- c++ parse int from string [duplicate]
- C++ array assign error: invalid array assignment
- Is there a median function in the C++ library?
- Determine if map contains a value for a key?
- how to initialize an empty integer array in c++
- What does |= mean in c++
- Error: cannot declare variable ‘c’ to be of abstract type ‘circle’
- Static linking vs dynamic linking
- error: called object type ‘int’ is not a function or function pointer
- Hash function for a string
- Is there a replacement for unistd.h for Windows (Visual C)?
- What is wrong with using goto?
- Double pointer array in c++
- Don’t understand static boolean behavior
- How to write std::string to file?
- Member declaration not found
- What is the difference between a .cpp file and a .h file?
- Stable Cotangent
- The CXX compiler identification is unknown
- Is there a standard sign function (signum, sgn) in C/C++?
- C++ compiler error: “return type specification for constructor invalid”
- error: ISO C++ forbids in-class initialization of non-const static member
- Function call missing argument list to create pointer
- cannot specify explicit initializer for arrays
- What does ** mean in C++?
- Incomplete type is not allowed: stringstream
- Initializing default values in a struct
- Warning: comparison of distinct pointer types
- MinGW .exe requires a few gcc dll’s regardless of the code?
- Converting bool to text in C++
- clearing a vector of pointers [duplicate]
- Evaluate a string with a switch in C++ [duplicate]
- C++ JSON Serialization
- stack around the variable…was corrupted
- Creating a list to hold objects in C++