Hello,
When i read the CLI spec, 8.10.2 Method inheritance i read the
following:
"A derived object type inherits all of the instance and virtual methods
of its base object type. It does not inherit constructors or
static methods...."
In the C# spec, 17.2.1 Inheritance i read the following:
"A class inherits the members of its direct base class. Inheritance means
that a class implicitly contains all members of its direct base class,
except for the instance constructors, finalizers, and static constructors
of the base class"
Consider the following code:
class A { public static void Method1() { } public static int X = 5;}
class B : A { }
Now i call B.Method1, which is translated to a call A.Method1 in IL.
The C# spec seems to mention that "static" means that members are
related to a specific type, instead of instances...
If C# really inherits all members, wouldn't that mean that the following
code should output 5 instead of the 10?
B.X = 10; Console.WriteLi ne(A.X);
To come to my question: Am i right when i say that in C# there isn't
true inheritance of static members?
--
Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/> 2 1994
On 2007-08-18, GlennDoten <gd****@gmail.c omwrote:
[snip large answer]
Thanks for your answer, i've been thinking it all over (drawing a couple
of venndiagrams and doing some proposition logic) and now i can see how
inheritance in c# maps to inheritance in the cli...
--
Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/>
GlennDoten <gd****@gmail.c omwrote:
Now i call B.Method1, which is translated to a call A.Method1 in IL.
I wouldn't say "translated ." The IL emitted by the compiler is what it
is because A.Method1 and B.Method1 are the very same thing because
Method1 is static.
<snip>
There are two issues here:
1) If the IL call were to B.Method1, that would force type B to be
initialized. By calling A.Method1 instead, type B can remain
uninitialized. This difference has been very significant to some people
in the past.
2) If a new B.Method1 is introduced without recompilation of the
calling code, that new method won't be called with the IL generated by
C#, but would if it generated IL calling B.Method1.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: porneL |
last post by:
How do I use static functions/properties with inheritance? I've found it
very problematic.
class Foo
{
static function A() {/* ??? */::B(); }
static function B() {echo 'Foo';}
};
class Bar extends Foo
|
by: wwight |
last post by:
As many people have noticed by now, PHP exhibits some frustrating
behavior when it comes to static fields and methods. For instance,
when a static method is defined in a parent class, but called from a
child class, the method uses the parent class for scope (not the
originating child class). For example, see the following block of
code:
class Parent {
private static $className = 'Parent';
|
by: Steve Jorgensen |
last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling
a particular case of implementation inheritance that would be easy and obvious
in a fully OOP language, but is not at all obvious in VBA which lacks
inheritance. I'm trying the explanation again now.
I often find cases where a limited form of inheritance would eliminate
duplication my code that seems impossible to eliminate otherwise. I'm getting
very...
|
by: Aaron Watters |
last post by:
A C# question about constructors/static methods and inheritance:
Please help me make my code simpler!
For fun and as an exercise I wrote somewhat classical B-tree
implementation
in C# which I later ported to java and Python for comparison.
http://bplusdotnet.sourceforge.net/ for full details and code
]
|
by: Ben Blank |
last post by:
I'm writing a family of classes which all inherit most of their methods and
code (including constructors) from a single base class. When attempting to
instance one of the derived classes using parameters, I get CS1501 (no method
with X arguments). Here's a simplified example which mimics the
circumstances:
namespace InheritError {
// Random base class.
public class A {
protected int i;
| |
by: burningodzilla |
last post by:
Hi all - I'm preparing to dive in to more complex application
development using javascript, and among other things, I'm having a hard
time wrapping my head around an issues regarding "inheritance" using
the prototype property. I realize there are no classes in JS, that code
therefore lives in objects instead of class definitions, and that
"inheritance" must be achieved prototypically and not classically.
That said, on with the code. Say I...
|
by: groups |
last post by:
C# is an impressive language...but it seems to have one big limitation
that, from a C++ background, seems unacceptable.
Here's the problem:
I have a third-party Document class. (This means I can't change the
Document class.) I want to extend this (inherit from Document) as
MyDocument, adding new events and application-specific methods and
properties.
|
by: Dave Rahardja |
last post by:
Since C++ is missing the "interface" concept present in Java, I've been using
the following pattern to simulate its behavior:
class Interface0
{
public:
virtual void fn0() = 0;
};
|
by: crjjrc |
last post by:
Hi, I've got a base class and some derived classes that look something
like this:
class Base {
public:
int getType() { return type; }
private:
static const int type = 0;
};
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |