Presentation is loading. Please wait.

Presentation is loading. Please wait.

one of the programming languages that you should know

Similar presentations


Presentation on theme: "one of the programming languages that you should know"— Presentation transcript:

1 one of the programming languages that you should know
C++ one of the programming languages that you should know

2 I am Piotr Klos I have read and I recommend: I have written: some basic Books, forums threads, documentation, source code in C++ „Design Patterns” by the „band of four” „Modern C++ Design” by Andrei Alexandrescu A stupid game called „Kartofel” Object Oriented Graphical User Interface „PKgui” A labyrinth editor, as a part of labyrinth generator

3 This presentation is about…
the theory behind C++ the advantages and disadvantages of C++ the significance of C++ in the modern programming

4 What is C++? a compiled programming language for general purpose
object oriented language based on C => supports procedural programming highly developed, standarised, language; its quality still increases safe <= strict static type checking enables generic programming <= templates

5 History of C++ Bjarne Stroustrup
first, poor version in 1979 „C with classes” ISO standard of C++ from 1998 growing popularity last standard in 2003 new version, C++ 0x is being developed

6 Object oriented? classes inheritance polymorphism
main ideas of the object oriented paradigm: classes inheritance polymorphism Object-based languages (like Visual Basic or JavaScript) do not have at least one of them.

7 Object oriented? classes – user defined types of objects with full rights correct example (red keywords): class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

8 Object oriented? have data class ClassName { private:
OtherClassName b; /// public: int a; /// ClassName* c; /// void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

9 Object oriented? data of in-build types class ClassName { private:
OtherClassName b; public: int a; /// ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

10 Object oriented? data of user defined types class ClassName { private:
OtherClassName b; /// public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

11 Object oriented? pointers, references, arrays, pointers to pointers, references to arrays of pointers, etc. class ClassName { private: OtherClassName b; public: int a; ClassName* c; /// void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

12 Object oriented? behaviour of objects : member functions, which process object data easily or do whatever you need class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { /// cout<<a; /// } /// ClassName(){/*a body*/ } /// ClassName(int arg){ a=arg; } /// ClassName(ClassName& ){/*a body*/ } /// ~ClassName(){/*a body*/ } /// ClassName operator+(ClassName & arg){ /// return ClassName(a+ arg.a); /// friend class OtherClassName; };

13 Object oriented? an ordinary function(prints the value of a)
class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { /// cout<<a; /// } /// ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); } friend class OtherClassName; };

14 Object oriented? constructors and copy constructors class ClassName {
private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } /// ClassName(int arg){ a=arg; } /// ClassName(ClassName& ){/*a body*/ } /// ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

15 Object oriented? destructors class ClassName { private:
OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } /// ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

16 Object oriented? overloaded operators
ClassName x(3),y(4); x=x+y; /*x.a==7*/ class ClassName { private: OtherClassName b; public: int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ /// return ClassName(a+ arg.a); /// } /// friend class OtherClassName; };

17 Object oriented? member protection
avoiding bugs and useless file dependencies class ClassName { private: /// OtherClassName b; public: /// int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; };

18 Object oriented? selective member protection class ClassName {
private: /// OtherClassName b; public: /// int a; ClassName* c; void f() { cout<<a; } ClassName(){/*a body*/ } ClassName(int arg){ a=arg; } ClassName(ClassName& ){/*a body*/ } ~ClassName(){/*a body*/ } ClassName operator+(ClassName & arg){ return ClassName(a+ arg.a); friend class OtherClassName; /// };

19 Object oriented? inheritance
NextClassName contains members of ClassName class NextClassName :public ClassName /// { int d; float z; };

20 Object oriented? Other OO-friendly idioms in C++ standard:
exception handling constancy of objects inlining easy to use dynamic memory allocation namespaces operator overloading encapsulation run-time type identification

21 Object oriented? to reflect the real world
OO, uniform, easy to use, in-build tools are used: to reflect the real world to reflect any beeings that exist only in our imagination to reflect any technical beeings in computer architecture OO paradigm is very powerful !

22 Examples of C++ code: literally everything at Microsoft
software by Adobe Systems Google search engine Apple OS X Havoc physics engine Metrowerks tools Mozilla Firefox most of big games

23 Is C++ Perfect? does not support multi-threading
most of C++ programmers complain, because C++: does not support multi-threading does not have delegates does not reflect some of design patterns – (more abstract beeings that cannot be defined as objects)

24 Is C++ Perfect? many C++ libraries have it C++ 0x will fix it
multi-threaded support: many C++ libraries have it C++ 0x will fix it so far no uniform multi-threaded support

25 Is C++ Perfect? many C++ libraries implement them C++ 0x may fix it
delegates: many C++ libraries implement them C++ 0x may fix it no uniform delegates

26 Is C++ Perfect? support for design patterns: What are design patterns? design pattern – named and formally described solution for a complicated problem

27 Is C++ Perfect? you can easily implement some of them using objects
support for design patterns: you can easily implement some of them using objects also some C++ libraries implement some of them those solutions are reusable but not very elegant and easy to use it will not change

28 Is C++ Perfect? support for design patterns: problems with dependencies between behaviours of objects theese cannot be defined only in terms of objects difference between set of notions used in project and structures written in code code does not reflect context of problem OO paradigm does not reflect worlds !!!

29 C++ is not perfect. we cannot easily translate some projects to a code with C++ because C++ is an OO language solution for this: aspect-oriented languages* *AO paradigm – introduced recently by Gregor Kiczales; there are already languages like AspectJ or AspectC++ which use it; visit

30 Why C++ is so popular? you can compile C code in C++
so you can use old C libraries in C++ so C++ supports linear, procedural, object-based programming, object oriented programming and data abstraction compiled C++ code is very efficient probably the most general purpose language in the world

31 general purpose… so there is a big community
so there are very many C++ libraries! so there is a competition so quality of code is very high so the quality of C++ standard is growing to meet the requirements other important reason…

32 generic programming in C++
templates – way of programming abstractions compiler generates similar parts of code instead of a programmer big C++ community produces a lot of template libraries examples: STL, Boost, Loki, others ready solutions for complicated problems fast, easy, safe and efficient programming

33 conclusion C++ is powerful
C++ and further versions will be used for a long time C++ influenced Java, C#, PHP, ADA95 etc. probably will influence others in the future it is worth to know


Download ppt "one of the programming languages that you should know"

Similar presentations


Ads by Google