Hi,
Say I have a abstract base class and I know that every derived class
will have a static data member (call it SharedInformati on)
representing information to be shared across all instances of that
derived class. However, this information will be differenet for each
derived class.
Now, if I define SharedInformati on as a static member of the base
class, then SharedInformati on cannot vary across the different derived
classes, because all derived classes will pointing to the same static
instance of SharedInformati on. However, if I don't define it in the
base class, then someone looking at the base class won't know that
every derived class must define a static data member
SharedInformati on.
How can I solve this problem? That is, have my base say, "All derived
classes will have a static data member called SharedInformati on" but
still be able to have different static instances of SharedInformati on
for each base class.
I know I may be looking at this problem in the wrong light. If so,
I'd appreciate any suggestions on how to re-conceptualize it.
thanks,
cpp
Jul 22 '05
10 1892
"JKop" <NU**@NULL.NULL > wrote in message
news:o2******** **********@news .indigo.ie... The result of this is that the student would understand polymorphism perfectly and entirely!
Hmmm.
When *I* first came to the chapter on polymorphism, I took one look at the word and made sure I was sitting up straight and paying full attention to the text, to try digest the whole thing. The name, "polymorphi sm", is stupid, it's like something out of biology - it implies that the concept
is much more complicated and hard to comprehend than it actually is!, when in essence it's just a nice pointer trick!
Hmmm. 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: Srini |
last post by:
Hello all,
I was just wondering about this. A const member function guarantees
constness of the object within the function body. But there's no way
for a member function to guarantee the constness of static members. Is
there a way to do that? Also, is there a way for a static member
function to guarantee constness of static members?
TIA
Regards,
|
by: Sunny |
last post by:
Hi all,
According C# Language Specification :
10.11 Static constructors:
The static constructor for a class executes at most once in a given
application domain. The execution of a static constructor is triggered
by the first of the following events to occur within an application
domain:
- An instance of the class is created.
|
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: Kirk Marple |
last post by:
Just want to see if this is 'by design' or a bug...
I have a common List<T> defined in a base class, and the base class has a
static property to expose this list.
I wanted the derived class to add items to this list, but have the base
class hold the data and expose the property.
Problem is, however, that the derived class' static constructor doesn't get
called when DerivedClass.MyList is accessed, so the list has no members. If
| |
by: Bill Rubin |
last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the same invocation from a DistantlyRelated class. What actually happened was that the compiler produced:
error C2247: 'A::function' not accessible because 'CloselyRelated' uses 'private' to inherit from 'A'
I'm guessing that the above compiler...
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you experts.
I would like to produce Javascript classes that can be "subclassed"
with certain behaviors defined at subclass time. There are plenty of
ways to do this through prototyping and other techniques, but these
behaviors need to be static and...
|
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: learning |
last post by:
Hi I have a static class written by other team which encapsulates a
database instance. but I need to extend it to incldue other things. I
know that C# static class is sealed and can;t be inherited & I don't
want to copy + paste code. How can I inherit those member variables?
Thanks
|
by: Tim Van Wassenhove |
last post by:
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:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |