Sign in to follow this  
nickme

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this