C++: Differences between C++ and C#

Contributor Icon Contributed by William_Wilson  
Tag Icon Tagged: Computer programming  

Key differences between C# and C++


It was a surprise that there was no thread for C++ recipes. Though C++ and C# are quite similar there are some very key and major differences.
-I find C# resembles the style of java more than that of C++ i many ways.

(I will be following this up with some coding recipes, to hopefully start a C++ reciped thread)

Method/Function Declarations:
C++:
public:
Constructor() { }
void aMemberFunction() { }
void aFunctionDeclaration();
private:
void someOtherFunction() { }
int aVariable;

C#:
private aVariable;
public void aMemberFunction() { }
public void aFunctionDeclaration();
private void someOtherFunction() { }

Class Declaration:
For those who know what a managed class is:
C++:
__gc class A_Class{ };
*NOTE that C++ classes end with a ;

C#:
automatically done so:
class A_Class{ }

Inheritence:
C++:
will allow multiple inheritence. eg. allows a method to be overriden many times in subclasses (derived classes).

C#:
supports inheritence, but not multiple, only 1 override per method/function/

Includes:
C++:
allows header files and other class files to be included using the #include keyword.

C#:
does not have such a quality, but the using directive allows other types to be referenced from another class (namespace as it is formerly called) without declaring it’s context.

Switch: *Props to PCurd for pointing out my careless mistake :)
C++:
supports the switch statement, and fall through.

C#:
does not support fall through in the switch statement, and i have not come across any replacement.

*These are the largest of the differences i have noticed so far, if i come across any further impending differences i will be sure to add them.

Questions/Comments: william_a_wilson@hotmail.com
-William. ยง (marvin_gohan)

 

6 Comments -


  1. Guidii said on January 13, 2009

    A couple others:

    Garbage collection (C#) vs programmer-managed memory (C++).
    No deterministic finalization in C#.
    C++ Templates are a compile-time concept, while C# generics are a run-time concept.

  2. nursingjob52 said on December 4, 2009

    Now these days most of the student learning this c++ software course because after this they can get good jobs.

  3. Jitendra Imh272 said on July 11, 2010

    u are the best in the word

  4. MEENA said on July 15, 2010

    i got my anser but i want some essy way

  5. Guest said on December 2, 2010

    you could cheap fall through with a loop around the switch incrementing the vallue

  6. Keithy said on December 2, 2010

    or you could just have a series of IFs (not IF-ELSE) and increment the value at the end of each IF statment

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -