InheritanceTests | Code for analyzing cpp inheritance | Compiler library
kandi X-RAY | InheritanceTests Summary
kandi X-RAY | InheritanceTests Summary
This is a collection of sample code which will construct classes with various inheritance models. It is intended to be used to test RTTI and class detection/reconstruction in reverse-engineering frameworks such as retdec and ghidra. This is what is being used to generate the program data for the test classes in the [Ghidra-Cpp-Class-Analyzer] A set of binaries compiled with various different architectures is available in the releases.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of InheritanceTests
InheritanceTests Key Features
InheritanceTests Examples and Code Snippets
Community Discussions
Trending Discussions on InheritanceTests
QUESTION
I am trying to learn the basics of inheritance in C#, and have realized there are gaps in my understanding of scope and accessibility. An example to illustrate:
...ANSWER
Answered 2017-Sep-04 at 00:10Regarding (+), why is the B instance's private field x accessible even after the cast to A?
Accessible to whom? In your example, B.Foo()
is called, because B
has overridden A.Foo()
(which is virtual
). Since the method being called is in fact in class B
, the method uses the x
field declared in B
. That's the only field x
that method can see.
The field x
in A
isn't visible to B
anyway, since it's private
. But if it were (i.e. if it were something other than private
), the field x
in B
would hide it and the B
implementation of Foo()
would still use x
from the B
class, not from A
.
Regarding (++), why when A's Foo method is executed does this.x not evaluate to 3?
In this example, the derived class C
has not overridden the original method Foo()
in A
. Instead, it's declared a whole new method Foo()
. But by casting the object back to A
, the compiler no longer knows about the method declared in C
. The only method it can see is A.Foo()
, which is not overridden, and so the A
implementation of Foo()
is called.
And of course, that implementation can see only the x
field declared in A
, where the method itself is declared. Hence, you get 1
in the output instead of 3
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install InheritanceTests
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page