C++

Functions with Default Arguments/Parameters

Posted on April 18, 2013. Filed under: C++ |

c++ functions can have default arguments.
For example, the following function takes default values if caller don’t supply any arguments.
int volume(int l=1, int w=2, int h=5);

volume() is explicitly volume(1,2,5)
volume(10) is explicitly volume(10,2,5)

Read Full Post | Make a Comment ( None so far )

Class and Objects, Placing Classes in Separate Files

Posted on April 18, 2013. Filed under: C++ |

C++ support Class and Objects. A Class need a access specifier.

We need to create an object of the class, before use functions inside the class.

A class file can be put into two files:
*.h header file, where we put the function prototypes and variable declarations.
*.cpp c++ source file, where the function body resides.

When a team of programmers work together or you need to distribute your programs to public, sometimes you don’t need or want others to change the class bodies, you only need to distribute the header files.

The .cpp file should have the include and namespace statements.

Aclass::Afunction, the :: is called binary scope resolution operator, it means Afunction is a member of Aclass.

There are two ways of accessing members inside a class.

One way is to use dot separator as java do: object.function()

Another way is to get the reference or memory address of the object, then use arrow member selection operator to access the class members: pointer->function()

#include <iostream>

#include “Sally.h”

using namespace std;

int main() {

Sally sallyObject; //create Object from Class

Sally *sallyPointer = &sallyObject; //assign the address of objet sallyObject to a pointer variable sallyPointer

sallyObject.printCrap(); //access function using dot separator

sallyPointer->printCrap(); //access function using arrow member selection operator

}

Read Full Post | Make a Comment ( None so far )

Introduction to Classes and Objects

Posted on April 17, 2013. Filed under: C++ | Tags: |

C++ support Class and Objects. A Class need a access specifier.

We need to create an object of the class, before use functions inside the class.

Read Full Post | Make a Comment ( None so far )

C++ Tutorial for Java and C programmers

Posted on April 17, 2013. Filed under: C++ |

This is a C++ tutorial mainly based on Buckys C++ Programming Tutorials, outofmylabortory’s C++ Basic Skills  on youtube. Assuming the readers have experience of other languages such as C and Java, this tutorial focus on C++ specific features and advanced topics.

C++ HelloWorld

Default function parameters

Unary Scope Resolution Operator

Pointers and Pass by Reference

Class, Object and Header files

Deconstructor

const keyword

Use member initializer list to initialize composite class

friend keyword

Operator Overload

Inheritance

Polymorphism and virtue keyword

C++ Generic Types

Read Full Post | Make a Comment ( None so far )

Understanding a Simple C++ Program

Posted on April 17, 2013. Filed under: C++ | Tags: |

This is an introduction to C++ hello world.

Concepts such as preprocessor, header, library, namespace, main, function, object, stream, return.

Read Full Post | Make a Comment ( None so far )

Next Entries »

Liked it here?
Why not try sites on the blogroll...