473,545 Members | 1,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What replace "this" in static class?

Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Applic ation class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Appli cation" object.
And previously I was using "this" keyword because the class inherit
from "QuickFix.Appli cation", but now that the class is static, is there
a keyword to point at this static class?

Thank you :)
Marty
Dec 7 '05 #1
6 2700
You can have static constructors.
class MyClass
{
// Static constructor:
static MyClass()
{
Console.WriteLi ne("The static constructor invoked.");
}
public static void MyMethod()
{
Console.WriteLi ne("MyMethod invoked.");
}
}

is the example in the help - calling MyMethod for the first time will
cause the constructor to be called.

I don't believe you can use "this" in a static class - I can't really
think of a reason to do so, either. Why do you want to do so?

Andy D

Dec 7 '05 #2
And previously I was using "this" keyword because the class inherit
from "QuickFix.Appli cation", but now that the class is static, is there
a keyword to point at this static class?


No. It needs an _instance of_ the class and by making your class
static you've made it impossible to create instances of it. Therefore
there's no way to do what you want.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 7 '05 #3
Hi,

There is no way of doing what you want, all you can do is get access to
the protected static fields of the parent class.

there is no way of doing what you were doing before.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Marty" <xm******@hotma il.com> wrote in message
news:urElf.1384 88$y_1.49549@ed tnps89...
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Applic ation class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Appli cation" object.
And previously I was using "this" keyword because the class inherit from
"QuickFix.Appli cation", but now that the class is static, is there a
keyword to point at this static class?

Thank you :)
Marty

Dec 7 '05 #4
Originally, your class, as a derived class of QuickFix.Applic ation,
held within it an instance of QuickFix.Applic ation. Now that it's is a
static class, this relationship is broken.

It fix this, you must make explicit what was previous implict. Your
class can no longer derive from QuickFix.Applic ation (as this relationship
is meaningless when one is a static class and the other is an instance
class), but should contain a explicit QuickFix.Applic ation member.

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Marty" <xm******@hotma il.com> wrote in message
news:urElf.1384 88$y_1.49549@ed tnps89...
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Applic ation class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Appli cation" object.
And previously I was using "this" keyword because the class inherit
from "QuickFix.Appli cation", but now that the class is static, is there
a keyword to point at this static class?

Thank you :)
Marty

Dec 7 '05 #5
Thank you everybody for your fast reply. Thinking that I might have no
"escape" I already restore my class to its previous state, being not
static. I think it will stay like that.

Have a nice day :)
Marty

Marty wrote:
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Applic ation class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Appli cation" object.
And previously I was using "this" keyword because the class inherit
from "QuickFix.Appli cation", but now that the class is static, is there
a keyword to point at this static class?

Thank you :)
Marty

Dec 7 '05 #6
Very interesting, thank you James.
Marty

James Curran wrote:
Originally, your class, as a derived class of QuickFix.Applic ation,
held within it an instance of QuickFix.Applic ation. Now that it's is a
static class, this relationship is broken.

It fix this, you must make explicit what was previous implict. Your
class can no longer derive from QuickFix.Applic ation (as this relationship
is meaningless when one is a static class and the other is an instance
class), but should contain a explicit QuickFix.Applic ation member.

Dec 7 '05 #7

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

Similar topics

5
1637
by: Yongming Wang | last post by:
FuncA is called to delete itself with B's help. In vc 7.0, case 1 seems invalid, but case 2 is valid. Could anyone explain for me? class A { public: void FuncA() { B b(this);
9
2169
by: aden | last post by:
I have read the years-old threads on this topic, but I wanted to confirm what they suggest. . . Can the this pointer EVER point to a type different from the class that contains the member function that the this pointer is being used in? That is, is the type of the this pointer always determined entirely syntactically (and never...
9
2358
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a class, if the class has more than than one cosntructor, by making sure that each constructor has a different signature. I have managed to learn that...
19
7908
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php on line 14
8
2227
by: solarin | last post by:
Hi all. I'm writting a logger class to write all the debug/info/warning/error messages in a file. Every time a class needs to send any message, should send a code (int) and a message (string). I would like to write also in the file, the class that has sent the message. all the clases that need to send a message, derives from a base clas: ...
10
2720
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
3
2499
by: arnuld | last post by:
this is from C++ Primer 4/e page 260: there is a class named Sales_item and same_isbn is a member function of that class. bool same_isbn(const sales_item &rhs) const { return isbn == rhs.isbn; } author says the word const modifies the type of implicit "this" paramater.
4
5300
by: dolphin | last post by:
Hi All I read a .cpp files,find that static void fun(void){......} int main() { .......... } What does this static function mean?Is it the same as the static
5
1823
by: DamienS | last post by:
Hi, I have a static method in a class and I need to be able to return a reference to "this". Googling around, I found a heap of discussions of the pros/cons of "abstract static" etc. It was quite a heated debate about purity of OO design that just did my head in a bit. In a nutshell. Can a static method 'know' what class it's defined in...
0
7401
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...
0
7656
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. ...
0
7807
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...
1
7419
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...
0
7756
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...
0
5971
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...
1
1879
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
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
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...

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.