Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 nickme   Members   -  Reputation: 193

Like
0Likes
Like

Posted 18 December 2012 - 01:04 PM

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.

Sponsor:

#2 EddieV223   Members   -  Reputation: 751

Like
0Likes
Like

Posted 18 December 2012 - 01:06 PM

[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, 18 December 2012 - 01:07 PM.

If this post was helpful and/or constructive please give rep.

SFML2.0 Nightly Download Link http://en.sfml-dev.org/forums/index.php?topic=9513.0

SFML2.0 Tutorials http://www.sfml-dev.org/tutorials/2.0/


#3 nickme   Members   -  Reputation: 193

Like
0Likes
Like

Posted 18 December 2012 - 01:39 PM

[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

#4 Strewya   Members   -  Reputation: 419

Like
0Likes
Like

Posted 19 December 2012 - 03:33 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS