473,761 Members | 7,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static virtual

I know that you can't have a static virtual property, but is there a
way to simulate the same results?

I have a base class that I want to extend so that you can change a
value and it inherits all of the methods to work with that value.
That's easy enough:

class BaseC {
string val;

public DoSomething() {
//manipulate val
}
}

class Derived : BaseC {
public Derived() {
val = "foo"
}
}

Derived.DoSomet hing() now manipulates "foo"

Now if I want BaseC to have static methods, that also manipulate
'val', I have to make val static. But when I have multiple derived
classes with static constructors, the static variable is for all of
the derived classes (bad).

I thought I could make static virtual properties that could just be
overloaded in the derived classes to return the correct value, but as
I stated, static virtual is not allowed.

Any Ideas?
Mark
Nov 16 '05 #1
2 3348
Try using the singleton design pattern. Make the Base a singleton. When
derived types get constructed, a single base is created for that derv
instance exclusively. This derv instance could manipulate the variable
originally defined in Base, and would not meddle with other derv's definition
as well.

"Mark" wrote:
I know that you can't have a static virtual property, but is there a
way to simulate the same results?

I have a base class that I want to extend so that you can change a
value and it inherits all of the methods to work with that value.
That's easy enough:

class BaseC {
string val;

public DoSomething() {
//manipulate val
}
}

class Derived : BaseC {
public Derived() {
val = "foo"
}
}

Derived.DoSomet hing() now manipulates "foo"

Now if I want BaseC to have static methods, that also manipulate
'val', I have to make val static. But when I have multiple derived
classes with static constructors, the static variable is for all of
the derived classes (bad).

I thought I could make static virtual properties that could just be
overloaded in the derived classes to return the correct value, but as
I stated, static virtual is not allowed.

Any Ideas?
Mark

Nov 16 '05 #2
I don't see how static virtual makes any sense.
How do you expect to manipulate instance variables of
a class from static methods of the same class?!?!
RayO
"Mark" <ma*****@rit.ed u> wrote in message
news:d4******** *************** ***@posting.goo gle.com...
I know that you can't have a static virtual property, but is there a
way to simulate the same results?

I have a base class that I want to extend so that you can change a
value and it inherits all of the methods to work with that value.
That's easy enough:

class BaseC {
string val;

public DoSomething() {
//manipulate val
}
}

class Derived : BaseC {
public Derived() {
val = "foo"
}
}

Derived.DoSomet hing() now manipulates "foo"

Now if I want BaseC to have static methods, that also manipulate
'val', I have to make val static. But when I have multiple derived
classes with static constructors, the static variable is for all of
the derived classes (bad).

I thought I could make static virtual properties that could just be
overloaded in the derived classes to return the correct value, but as
I stated, static virtual is not allowed.

Any Ideas?
Mark

Nov 16 '05 #3

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

Similar topics

2
33179
by: john smith | last post by:
I'm wondering if it's possible to declare a pure virtual member function? Ie is: class A{ public: virtual static void f() const = 0; }; legal? I'm getting compile errors for code that used to work before I added the changes in, and I'm not sure if that's causing it.
3
2524
by: Philippe Guglielmetti | last post by:
Look at these few lines of code: class A { public: virtual void f() { cout << "A";}}; class B : public A{public: static void f() { cout << "B"; }}; class C : public B{public: void f() { cout << "C"; }}; // virtual or not ? that's the question... int main(int, char**) { A* x; A a; B b; C c;
7
1513
by: qazmlp | last post by:
What do you recommend among the following two designs, considering all the standard design aspects ? 1) class base { public: virtual ~base() { } virtual long int getId() = 0; private:
6
5834
by: Dumitru Sipos | last post by:
Hello everybody! is there possible to have a function that is both static and virtual? Dumi.
5
651
by: Tony Johansson | last post by:
Hello experts! Why is not possible to have virtual static members Many thnakn //Tony
15
3504
by: Philipp | last post by:
Hello I don't exactly understand why there are no static virtual functions. I would have liked something like this: class Base{ static virtual std::string getName(){ return "Base"; } }
1
3536
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the following (with incomplete succes): I want in a given namespace Parameters a list of "initializers" (which are objects derived from a simple interface that can be implemented anywhere, and are used to define which parameters the program will take at...
8
2888
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; };
6
4002
by: Jia | last post by:
Hi all, I have a class foo which has a static vector of pointers of type base class, and a static function to set this vector. #include <iostream> #include <vector> using namespace std; class super{ protected:
2
2412
by: cmonthenet | last post by:
Hello, I searched for an answer to my question and found similar posts, but none that quite addressed the issue I am trying to resolve. Essentially, it seems like I need something like a virtual static function (which I know is illegal), but, is there a way to provide something similar? The class that is the target of my inquiry is a template class that interfaces to one of several derived classes through a pointer to a base class. The...
0
10115
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
9957
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
9905
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
9775
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
8780
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...
1
7332
isladogs
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...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
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
3
2752
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.