Tuesday, November 19, 2024
HomeComputer programmingC++: Differences between C++ and C#

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

The key differences between C# and C++ are explained in the following tech recipe.


Though C++ and C# are quite similar, there are some very key and major differences. In fact, I find C# resembles the style of java more than that of C++ in many ways.

(I will be following this up with some coding tutorials to hopefully start a C++ tech-recipe 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++:
This will allow multiple inheritance. [e.g., allows a method to be overridden many times in subclasses (derived classes)].

C#:
This will support inheritance, but not multiple (only one override per method/function/).

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

C#:
This 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 its context.

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

C#:
This does not support fall through in the switch statement, and I have not discovered any replacement.

*These are the largest of the differences I have noticed so far. If I find any other impending differences, I will be sure to add them.

Questions/Comments: [email protected]
-William. § (marvin_gohan)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!