introduction C++

danke.. danke..

thanx for all the attention to me..

😀

it’s my first official practice on C++. I’ve found many new things on this paradigm, OOP-object oriented programming. Maybe I’ll share some good things to be remembered for a C++ starter.

  • Nowadays, we use a new compiler for c++, for example GCC(the up-to-date one), visualC++, cygwin, etc. There are some differences about how to code in each compiler. The new one doesn’t need to put .h on each included function as iostream, fstream, etc. Here the rules:

//file coba0.cpp
#include

int main()
{
cout<<"hai hai.."<When we started learn to code C language that script seems similar. And of course you can write it like that, because C++ is an impure OOP language. But, it works only at old versions of C++ compiler. So if that code is compiled at newer compiler your code may be wrong.  You should start to write like this:

//file coba.cpp
#include
int main()
{
std::cout<<"hai hai.."<See the difference?! the library inclusion doesn’t need ‘.h’. Because of this, you must add each iostream function with its class at first. But it’s must be tiring to add std:: everytime we call cout and cin function of iostream. So basically you just put “using namespace std;” globally, like this:

//file coba.cpp
#include
using namespace std;
int main()
{
cout<<"hai hai.."<why we shouldn’t use iostream.h anymore? I’ve quoted the answer from gamedev.net:

There are several reasons why new code should be written using the extensionless version of the header files instead of the .h forms. The first is the unpredictability of such code when compiled on modern compilers. As previously mentioned, the result of using the .h headers is implementation specific. And as time goes by, the chance that a given compiler will have the old style library available decreases.

Even given a compiler that has the CFront iostream library available, there are concrete benefits to using the standard version. For one thing, the standard version has an interface that is exception aware. This includes both defining exceptions that the iostream library may throw, but also reducing the number of ways that the iostream library may be interfaced in exception unsafe ways. For example, elimination of two stage construction of iostream objects reduces the possibility of leaking resources.

The new style iostreams also integrate better with the rest of the Standard C++ Library. The best example of this is using istreambuf_iterators to load an entire file into a container.

Also, the standard C++ library has better localization support. This includes the use of locales with stream objects to handle things such as determining if a “.” or a “,” is used as a decimal seperator. It also includes wide character support to handle a larger range of local characters.

  • don’t ever forget to add semicolon after “}” at the end of the class. It has troubled me in the first time. At that time, I have been searching for a day to find that mistake. The implementation itself doesn’t need it.

class rizky
{
public:
void kick();
void throwAway();
private:
int parts;
}; //<---DON'T EVER FORGET THIS LITTLE BUNNY ";" //implementation void rizky::kick() { //......write some codes here...... } //<----------you don't need to add semicolon here void rizky::throwAway() { //......write some codes here...... } //<---you don't need to add semicolon here [/sourcecode] okay... that's it for today!!

Satu pemikiran pada “introduction C++

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s