I'm a necromancer.
Thommo said:
Could anyone tell me if there is anything that makes C++ unique... i cant find any info on it anywhere. help would be really apreciated.
Partially taken out of "C++: The Complete Reference, fourth edition" by Herbert Schildt
C++ supports OOP (Object Orented Programming).
C++ supports Polymorphism (which is characterised by the phrase "One interface, multiple methods")
C++ supports RTTI (Run Time Type Identification) which is used in OOP classes and structures.
C++ supports Inheritance (Where one class is derived from another (base) class)
C++ allows the declaration of "empty" functions.
Code:
C type declaration: int Foo(void);
C++: int Foo();
C++ (and C99) does NOT default it's data type to an integer if no data type is given.
C++ introduces the bool data type;
C++ introduces namespaces:
Code:
namespace Moo{
function Foo(){ cout << "Moo's Foo!\n";}
};
namespace Meow{
function Foo(){ cout << "Meow's Foo!\n";}
};
using namespace Moo{
Foo();
}
using namespace Meow{
Foo();
cout << "Calling Moo's Foo() from inside Meow.\n"
Moo::Foo();
}
will output
Code:
Moo's Foo!
Meow's Foo!
Calling Moo's Foo() from inside Meow.
Moo's Foo!
C++ introduces classes; this is the most important feature of C++. In order to create an object, you must first define it by using the class keyword. A class is similar syntactically to a structure.
Classes have 3 access levels:
Public - The member may be accessed by anything.
Private - The member may only be accessed by the same object.
Protected - The member may be accessed by any object derived from the class, or may be accessed by its self.
Constructors and Destructors:
Class constructors are called when the class is created, and destructors are called when they are destroyed.
The basic syntax is:
Code:
class _SchoolClass{
public:
int num_of_students;
int num_of_males;
int num_of_females;
char* TeacherName;
char* Subject;
_SchoolClass() { //Constructer
num_of_students = 30;
num_of_males = 15;
num_of_females = 15;
TeacherName = new char[70];
Subject = new char[30];
sprintf(TeacherName,"Mr. FooBar");
sprintf(Subject,"C++ Programming");
printf("I have created a %s class, being taught by %s; %s's class has %d students: %d males and %d females.", Subject,TeacherName, TeacherName, num_of_students, num_of_males, num_of_females);
}
~_SchoolClass(){ //destructor
printf("%s's %s class has graduated, Huzzah!\n",TeacherName,Subject);
delete TeacherName;
delete Subject;
}
};
this will output
Code:
I have created a C++ Programming class, being taught by Mr. FooBar; Mr. FooBar's class has 30 students: 15 males and 15 females.
Mr. FooBar's C++ Programming class has graduated, Huzzah!
C++ supports overloading.
One way that C++ achieves Polymorphism is through Overloading. Two or more functions can share the same function name sas long as thier parameters are different.
Code:
void Say(){
cout << "I am a mute, because of my lazy programmer.\n"
}
void Say(char* text){
cout << "Say said: \'"<<text<<"\'\n";
}
void Say(int num){
cout << "Your lucky number is "<<num<<".\n";
}
Say();
Say("Mooooo.");
Say(3);
will output:
Code:
I am a mute, because of my lazy programmer.
Say said: 'Moooooo.'
Your lucky number is 3.
I have spent ~30 minutes writing this so I hope it is helpful to others.
There is still much more, but I'm short on time right now.
I may get back and write more later.