Jump to content

  • Log In with Google      Sign In   
  • Create Account


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: 205

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: 1263

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.1 Download http://www.sfml-dev.org/download.php

SFML2.1 Tutorials http://www.sfml-dev.org/tutorials/2.1/

 

// 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   -  Reputation: 205

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: 970

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