473,626 Members | 3,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static consts and inheritance

Hi

I have an abstract class that contains 100% static methods and variables.

One of the member variables "string DatabaseName" needs to be overridden in
derived classes.
Am I able to keep my class as totally static and do this? If so then how
please?

(I dont want to create an instance of the derived class just to query a
const string)

thanks
Claire
Jul 14 '06 #1
4 2075
Hi,

"Chukkalove " <so*****@micros oft.comwrote in message
news:ey******** *****@TK2MSFTNG P05.phx.gbl...
Hi

I have an abstract class that contains 100% static methods and variables.
Why you have something like this? static could be seeing as the opposite of
abstract.
One of the member variables "string DatabaseName" needs to be overridden
in derived classes.
Am I able to keep my class as totally static and do this? If so then how
please?
Why you want to have them static in the first place?
Have you seeing the Singleton pattern? Maybe that's what you are after
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jul 14 '06 #2

Chukkalove wrote:
Hi

I have an abstract class that contains 100% static methods and variables.
In order that a class be abstract, it must have at least one abstract
member, and static members cannot be abstract, so I don't know how you
did this.
One of the member variables "string DatabaseName" needs to be overridden in
derived classes.
That makes no sense. "Override in derived classes" means polymorphism,
and polymorphism works only with class instances. Since your class is
entirely static, and therefore (presumably) you would want the
"overridden " thing to be static in the child class as well, I don't
understand what you're after.
Am I able to keep my class as totally static and do this?
Absolutely not. However, I think that the problem here is one of
terminology or design. Could you step back a few paces and describe the
effect you're trying to achieve and the problem you're trying to solve?
Maybe there's a different solution for your problem, or maybe we just
misunderstand what it is you need to do.

Jul 14 '06 #3
Bruce Wood <br*******@cana da.comwrote:
Chukkalove wrote:
I have an abstract class that contains 100% static methods and variables.

In order that a class be abstract, it must have at least one abstract
member, and static members cannot be abstract, so I don't know how you
did this.
You don't have to have any abstract members to make a class abstract:

abstract class Test
{
static void Main() {}
}

compiles fine.

What doesn't make sense (amongst other things) is the idea of an
abstract *variable*. Variables can't be overridden...

--
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
Jul 14 '06 #4
Chukkalove wrote:
I have an abstract class that contains 100% static methods and variables.

One of the member variables "string DatabaseName" needs to be overridden in
derived classes.
Am I able to keep my class as totally static and do this? If so then how
please?
abstract class StaticBase
{
public static string Name = "StaticBase ";
}

abstract class StaticDerived : StaticBase
{
new public static string Name = "StaticDerived" ;
}
Note to other repliers: a "static" class would make more sense, in 2.0
.... except that a static class can only derive directly from object.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Jul 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2503
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
4
5417
by: cppsks | last post by:
"Defining static const variables inside the class is not universally supported yet, so for now I guess you'll have to move the definition out of the body of the class. No, static const inside classes is only allowed for integral consts, like static const enum and static const int, not for arrays and structs. It does make sense for an array of integral consts though." I read the above statements in this group a while back. First off,...
4
2832
by: trying_to_learn | last post by:
I'm learning consts in C++ and the book says that u have to initialize non-static consts inside the constructor initializer list, however "const string* stack" isn't initialized in the constructor initializor list,instead its initialized inside the constructor main body using memset.I dont understand this,why isnt this uniform class StringStack { static const int size = 100; const string* stack; int index;
19
7706
by: cody | last post by:
Iam wondering what the benefit of using const over static readonly is. static readonly is a runtime constant and can be set once in the initializer or the static ctor, whereas const is suffering from binary incompatibility since it is hardbaked into the binary. I do not believe there is a performance advantage with using const over static readonly since the JIT will take account of that or am I wrong here?
8
2052
by: Fernando Lopes | last post by:
Hi there! Someone has some code sample about when is recommend use a statis method? I know this methos don't want to be initialized and all but I want to know when I need to use it. Tks. Fernando
3
6606
by: dj | last post by:
Perhaps this question should be in the standard c newsgroup, but i hope somebody answers it here. Anyway, I came across this situation in an otherwise c++ code. I need a struct that works like some sort of a flag set. The flag mask is a single long, while the meaning of individual flags is given by static const members of the same struct: struct flag_set { long flags;
5
2996
by: Sek | last post by:
hi folks, i have a bunch of strings used in my code in many places. these strings reside inside a instantiable class. so, i want to replace these with constant/static variable to control the occurences. i have been looking at both static and const variables as the options, but couldn't decide on one.
2
1994
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:
1
2552
by: rmdeboer82 | last post by:
I've read this thread (couldn't do a post): http://www.thescripts.com/forum/thread653679.html How is this called: CClass SomeInstance Is it a definition? I assume it is because memory is allocated, however according to the info at the previous thread:
0
8707
Oralloy
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...
0
8641
jinu1996
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...
1
8366
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,...
0
8510
tracyyun
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...
0
7199
agi2029
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...
0
5575
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();...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.