Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jollyjeffers

'Shared' keyword in C++ ?

This topic is 5593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, This might seem a little odd, but is there an equivelent keyword/syntax structure to the ''Shared'' keyword in the .Net languages? I''m alright with C++, but I come from a VB/Java/C# type background - so there are a few things I take for granted there that are confusing me in C++ Recently I put a Shared function into a VB.Net app - you add the shared keyword and you can access it like: MyClass.MySharedFunc(...) rather than Dim X as MyClass X.MySharedFunc(...) ie, you dont need to instantiate the class before you use it. I''ve looked through Stroustrup''s C++ book and cant see anything that''d do this - so is it just a high(er)-level thing or am I missing something? regards, Jack DirectX 4 VB: All you need for multimedia programming in Visual Basic Formula 1 Championship Manager, My Game Project.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by jollyjeffers
This might seem a little odd, but is there an equivelent keyword/syntax structure to the ''Shared'' keyword in the .Net languages?


".Net languages" don''t have a Shared keyword - thats just VB.NET.
quote:

I come from a VB/Java/C# type background


Then you should know that the Java and C# equivalent of Shared is static.

It is the same in C++.





"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe

Share this post


Link to post
Share on other sites
quote:
Then you should know that the Java and C# equivalent of Shared is static.


fair enough I''ve not used the keyword in C# (assumed it was the same - woops). I did know it was static in Java tho... my bad!

the reason i didn''t think it was static was because I kept getting compiler errors when using it. I''ll have another go..

Jack

DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.

Share this post


Link to post
Share on other sites
I get the error:

quote:
h:\Visual C++ Files\DirectX9\SimpleD3D9\Gfx3D.cpp(123): error C2724: ''Gfx3D::IsDisplayModeOkay'' : ''static'' should not be used on member functions defined at file scope


the relevent lines of code:


//in the public section of the class Gfx3D definition:
bool static IsDisplayModeOkay(int iW, int iH, int iD);

//this is the actual code implementation:
bool static Gfx3D::IsDisplayModeOkay(int iW, int iH, int iD) {
//not yet implemented
return true;
}


I''ve tried moving the ''static'' around, but I dont get any difference. The MSDN help files haven''t helped me either

any hints!?

cheers
Jack

DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.

Share this post


Link to post
Share on other sites
You just write static in the funcion/method definition, like this:


// header file
class SomeClass {
// ...
static int someMethod( void );
}

// implementation
int SomeClass::someMethod( void ) {
// ...
}


IIRC, this is because otherwise you''d try to declare a really strange static int.

Share this post


Link to post
Share on other sites
quote:
Original post by jollyjeffers
fixed it - you only need static in the definition in the class, not the actual implementation.


"C++ is like an Old Testament God, with lots of rules and no mercy".



"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe

Share this post


Link to post
Share on other sites
quote:
Original post by null_pointer
No, VB misspells static as shared.

Shared is closer to the intent. I''ve always thought that static could be confused for "const", if you take the dictionary meaning. Oh, and The World''s Greatest Programming Language (tm) also uses "shared", so there!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!