Jump to content

Image of the Day

What's the best way to move your heavy stuff? Using a power loader! #spacr #screenshotsaturday 💪🤖💪 https://t.co/sOjz2XNVeq
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

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

4: Adsense

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   

253
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.

#2 EddieV223   Members   

1839
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 or signature was helpful and/or constructive please give rep.

 

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

 

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

 

// Excellent 2d physics library Box2D

http://box2d.org/about/

 

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

 


#3 nickme   Members   

253
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   

2684
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.

devstropo.blogspot.com - Random stuff about my gamedev hobby





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.