Sign in to follow this  

how to define a class with features like c#'s static class?

This topic is 1855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi

i am new to c++ OOP. how do i define a C#'s static class where i can define a set of static methods to be used in C++? i came across a website that said i can use CBox::show(); to call the method show in class CBox, but i forget about the details and where the website is. can someone send me a link or an example?

thanks.

Share this post


Link to post
Share on other sites
[source lang="cpp"]class MyStaticClass
{
public:
static int myInt;
static void MyFunc();
};[/source]

There are no static constructors though. So you have to take care of that some where.

Because there are no static ctor, you maybe just use a singleton. Edited by EddieV223

Share this post


Link to post
Share on other sites
[quote name='EddieV223' timestamp='1355857601' post='5012138']
[source lang="cpp"]class MyStaticClass
{
public:
static int myInt;
static void MyFunc();
};[/source]

There are no static constructors though. So you have to take care of that some where.

Because there are no static ctor, you maybe just use a singleton.
[/quote]

thanks

Share this post


Link to post
Share on other sites
or you can just put your functions in the same or different namespace as free functions. C++ doesn't need to have stuff in a class like C# does. and if you have any static variables, you're gonna have to initialize them outside of functions anyway, so it's pretty much the same thing.

Share this post


Link to post
Share on other sites
Sign in to follow this