Professional Documents
Culture Documents
Introduction To C++: C++ Is An Object Oriented Language It's An Extension To C
Introduction To C++: C++ Is An Object Oriented Language It's An Extension To C
PEACOCK
SPARROW
KINGFISHER
OWL
bool
delete namespace protected throw
catch
explicit new this virtual
class
friend public try typeid
CLASS
A Class has a structure as follows :
class class_name { member function 1 (); member function 2 (); member function n (); };
FUNCTIONS
Functions are of 4 kinds : No return no argument : void hello(); No return vid argument : void hello(int x); Return with argument : int hello (int x); Return with no argument : int hello();
OBJECTS
Objects are the pre instance of a class. An object acquire all the properties that a class has. Objects are created as : Class_name Object_name; Likewise the functions defined in class are called through this object. Object_name. member function;
ios_base : The ios_base class is designed to be a base class for all of the hierarchy of stream classes, describing the most basic part of a stream, which is common to all stream objects. Therefore, it is not designed to be directly instantiated into objects. ios : Both this class and its parent class, ios_base, define the members of all standard streams that are independent of whether the stream object is an input or an output stream. istream : istream objects are stream objects used to read and interpret input from sequences of characters. Ostream : ostream objects are stream objects used to write and format output as sequences of characters.
TYPECASTING
Conversion of mathematical data types from one to another.
NAMESPACES
Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name. They are written as : Namespace xyz { int a,b,c; } And this namespace variables can be called in the program as : xyz :: a; Also keyword using can be used to specify the namespace: Eg: using xyz :: b;
FUNCTION OVERLOADING
In C++ two different functions can have the same name if their parameter types or number are different.
#include <iostream> //using namespace std; int operate (int a, int b) { return (a*b); } float operate (float a, float b) { return (a/b); } int main () { int x=5,y=2; float n=5.0,m=2.0; cout << operate (x,y); cout << "\n"; cout << operate (n,m); cout << "\n"; return 0; }
INLINE FUNCTION
An inline function is used to suggest to the compiler that the code generated by the function body is inserted at each point the function is called, instead of being inserted only once and perform a regular call to it. The syntax of inline func. Is : Inline function_name (arguments...) {instructions...}
ACCESS SPECIFIERS
The access specifier determines the access to the names that follow it, up to the next access specifier is declared. There ae 3 access specifiers : Public Private Protected
FRIEND FUNCTION
In order to access non-public members of a class outside we use friend function.
<STRING.H>
INHERITANCE
Dynamic_cast class CBase { }; class CDerived: public CBase { }; CBase b; CBase* pb; CDerived d; CDerived* pd; pb = dynamic_cast<CBase*>(&d); // ok: derived-to-base pd = dynamic_cast<CDerived*>(&b); // wrong: base-to-derived
const_cast This type of casting manipulates the constness of an object, either to be set or to be removed. For example, in order to pass a const argument to a function that expects a non-constant parameter: // const_cast #include <iostream> using namespace std; void print (char * str) { cout << str << endl; } int main () { const char * c = "sample text"; print ( const_cast<char *> (c) ); return 0; }
POINTERS
REFERENCE
A reference is similar to a pointer. But has subtle difference from a pointer. Eg: int i=10; int &j = i;