The Binary Zoo
Welcome, Guest. Please login or register.
May 21, 2013, 01:32:46 AM

Login with username, password and session length
Search:     Advanced search
Welcome to The Binary Zoo.

Please do not feed the animals.
29633 Posts in 1431 Topics by 164 Members
Latest Member: Martoon
* Home Help Search Calendar Login Register
+  The Binary Zoo
|-+  General
| |-+  Game Development
| | |-+  C++ and C# Differences?
« previous next »
Pages: 1 [2] 3 4 ... 6 Go Down Print
Author Topic: C++ and C# Differences?  (Read 4717 times)
Prime_8
Bunnymonkey
*****
Offline Offline

Posts: 1207



View Profile WWW
« Reply #15 on: August 23, 2011, 01:48:51 PM »

and in same cases classes have 'special' powers dependin' on the lib you use.

::

if you have some private vars .


Code:

class myClass {
   private int myVar;

   public int myFunc() { return myVar;  }; // inline , as it's just to simple not to do this .

};



Code:

myClass MyObject;

int IntegerFromClass  = MyObject.myFunc();

protecting and controlling access , as the class creator


lol well i think you get the point.

proper OOP forces "good" coding habbits a bit more.. but i say .. stick it !.. LOL

if you have implimentations in .h ,  it is mor efor your compiler to do .. each compile, & you can run into cross links and scope issues.

.h ---

#ifnodef  THISHEADERNAME ;
#define THISHEADERNAME = 1 ;

//put your header junk in here ...
// if your headre is call else where by some other .h or .cpp , its will be skipped over, preventing re declarations

#endif;

, is some .cpp you can do this

bool header = 1 ;
#ifnodef THISHEADERNAME ;
header = 0;
#endif;

?? oh and .cpp , once compiled into a object , your compiler won't recompile it unless you change the somethingin teh source file , or you force a full recompile.

lol , well something like that
Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #16 on: August 24, 2011, 05:34:07 PM »

Interesting stuff Prime.  Thanks.

Funny you should mention accessing private vars as it doesn't look like C++ supports Properties which I used a lot in C# once Paul Cunningham explained their benefits.

Guess I'll just have to use Get/Set functions instead. Smiley
Logged

JDog053
Playtester
Bunnymonkey
*******
Offline Offline

Posts: 1690



View Profile
« Reply #17 on: August 24, 2011, 07:36:47 PM »

Interesting stuff Prime.  Thanks.

Funny you should mention accessing private vars as it doesn't look like C++ supports Properties which I used a lot in C# once Paul Cunningham explained their benefits.

Guess I'll just have to use Get/Set functions instead. Smiley

C++ does support all the standard 3 types of security for variables. by default they're all private, but you can if you want make them public or protected in the header file but its done differently...

Code:

class Object{

public:
   float f;
   int i;

protected:
    string s; //strings aren't default supported
    char c;

}


syntax me be wrong but thats what you do! Tongue
Logged

Projects - Tile Engine/Editor, Platformer Game.
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #18 on: August 26, 2011, 06:04:25 PM »

Interesting stuff Prime.  Thanks.

Funny you should mention accessing private vars as it doesn't look like C++ supports Properties which I used a lot in C# once Paul Cunningham explained their benefits.

Guess I'll just have to use Get/Set functions instead. Smiley

C++ does support all the standard 3 types of security for variables. by default they're all private, but you can if you want make them public or protected in the header file but its done differently...

Code:

class Object{

public:
   float f;
   int i;

protected:
    string s; //strings aren't default supported
    char c;

}


syntax me be wrong but thats what you do! Tongue

Yeah thanks I'm using those protection levels already.  I just miss the extra control that using a Property accessor gives you in C# Smiley

Quite liking C++ now that I've adjusted to it's little quirks.
Logged

Prime_8
Bunnymonkey
*****
Offline Offline

Posts: 1207



View Profile WWW
« Reply #19 on: August 26, 2011, 11:16:41 PM »

and C++ can use its lil' bro C , via #externC or such adding even more access to other 3rd party dll and libs.
Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #20 on: August 28, 2011, 09:25:44 AM »

and C++ can use its lil' bro C , via #externC or such adding even more access to other 3rd party dll and libs.
Yeah a part of my decision to look at C++ was obviously all the extra libs I can play around with although for multi-platform compatibility I will have to use them carefully.

Right now my plan is to "finish" each project so that it is entirely cross platform and only then maybe add a few extras like (shaderzzz to the PC build, Gamecenter to iOS etc).

Just making it up and learning as I go along though which is the way I enjoy doing things.
Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #21 on: September 01, 2011, 08:38:54 AM »

C++ doesn't like cross references between classes and files does it.  I've never seen as many error messages in my life lol  Shocked

Logged

Prime_8
Bunnymonkey
*****
Offline Offline

Posts: 1207



View Profile WWW
« Reply #22 on: September 03, 2011, 05:20:56 AM »

lol, no kidding .

Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #23 on: September 04, 2011, 09:10:06 AM »

What's the easiest way of gaining access to a load of different classes spread across numerous files?  Rather than #including them all can I just use a single "Using Namespace...." call?

In C# I had things in separate files and all using the namespace and that seemed to work but I'm not sure about in C++
Logged

PaulCunningham
Playtester
Elephant
*******
Offline Offline

Posts: 360



View Profile WWW
« Reply #24 on: September 06, 2011, 01:27:56 PM »

What's the easiest way of gaining access to a load of different classes spread across numerous files?  Rather than #including them all can I just use a single "Using Namespace...." call?

In C# I had things in separate files and all using the namespace and that seemed to work but I'm not sure about in C++


http://webcache.googleusercontent.com/search?q=cache:Gk0s2Ab_uXcJ:tek3d.org/organizing-code-files-in-c-and-c+Organising+Code+Files+in+C+and+C%2B%2B+-+by+Ben+'Kylotan'+Sizer&cd=13&hl=en&ct=clnk&gl=uk

This is a good free online resource.
http://www.parashift.com/c++-faq-lite/

and you'll need one of these...
http://www.paulnettle.com/pub/FluidStudios/MemoryManagers/Fluid_Studios_Memory_Manager.zip

PS - I'd never, ever go back to C++.
Logged

Cheers,
Paul Cunningham
Pumpkin Games
fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #25 on: September 06, 2011, 05:28:47 PM »

Thanks for the links Paul.  That first one is great and answers my linking questions.

PS - I'd never, ever go back to C++.
I think if I'd started with C++ it wouldn't be too bad, but coming from C# it's not very coder friendly.
Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #26 on: October 07, 2011, 08:40:42 AM »

My first C++ WTF moment last night.....although it took slightly longer than a "moment" to find the cause.  Tongue

I hadn't initialised an array but C++ was more than happy to let me use it, something that C# wouldn't let you do.

The thing that really threw me was that it's an array used to store data I use for my screen flashing routine (for explosion) and the data in the bit of memory the array was accessing just happened to give me the results I was expecting.  It was only after running the screen flash routine a few times that the data got corrupted and it gave unexpected results.

Hey it's all a learning process  Smiley
Logged

JDog053
Playtester
Bunnymonkey
*******
Offline Offline

Posts: 1690



View Profile
« Reply #27 on: October 07, 2011, 05:24:43 PM »

C++ loves doing that, you can do pretty much anything... which is good and bad in equal measure.
Logged

Projects - Tile Engine/Editor, Platformer Game.
Prime_8
Bunnymonkey
*****
Offline Offline

Posts: 1207



View Profile WWW
« Reply #28 on: October 08, 2011, 08:58:33 AM »

hehe , that sort of pointer acces  , being blind to true content can allow for some truely random stuff.

#include <assert.h>

is handy ..

ie
sysCursor = LoadWinImage( LuaT.GetGLobalString("Cursor_3D_main"));
        assert (sysCursor!=NULL);

this will pop up a window telling me the command line assert is on , if it is not true .

so for debugging it is a grand tool.

but can allow you to halt or continue .

allows you to be sure your objects and such are being setup like needed.

Logged

fog
Binary Zoo
Zookeeper
Bunnymonkey
*****
Offline Offline

Posts: 12643



View Profile WWW Email
« Reply #29 on: October 08, 2011, 12:12:31 PM »

hehe , that sort of pointer acces  , being blind to true content can allow for some truely random stuff.

#include <assert.h>

is handy ..

ie
sysCursor = LoadWinImage( LuaT.GetGLobalString("Cursor_3D_main"));
        assert (sysCursor!=NULL);

this will pop up a window telling me the command line assert is on , if it is not true .

so for debugging it is a grand tool.

but can allow you to halt or continue .

allows you to be sure your objects and such are being setup like needed.
Cool.  I wasn't aware of assert.

The only problem I've got is that for the most part everything I do has to be multi-platform so I can only use libraries that are available on all of those.  There are obviously exceptions to this, but where I can I'm sticking to that.

Although TBH it's not proving too much of a problem as I'm learning C++ as I go and I'm not aware of what great libraries I'm not able to use lol.  Smiley
Logged

Pages: 1 [2] 3 4 ... 6 Go Up Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!