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.
how to define a class with features like c#'s static class?
[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.
{
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.
[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.
thanks
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement