1 / 10

C++

C++. A word concerning C++ and Object Oriented (OO) Programming C++ became the de facto standard and grew from the need of an object oriented programming method. OO programming can be accomplished by virtually any language. C, assembly, some proprietary languages can be used.

Download Presentation

C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ • A word concerning C++ and Object Oriented (OO) Programming • C++ became the de facto standard and grew from the need of an object oriented programming method. • OO programming can be accomplished by virtually any language. • C, assembly, some proprietary languages can be used. • C++ formally standardized OO based upon the C standard. • C++ is a tool that allows data encapsulation to be combined with operations (methods) into a data structure known as a class. • C++ allows its data structures to be used as building blocks for other data structures known as inheritance. • C++ allows a concept known as polymorphism which is the ability of a method or operator to be used in varying ways. The method of the derived class redefines the method of the base class (virtual).

  2. C++ • Review • What do we need to have a C++ program? • Have to have an idea of what you want to do. • Have to have a main() • Have to have some objects that you want to use. • <iostream> • std namespace • Have to have tools to compile, edit, and run the program.

  3. C++ • Review cont’d • Declarations (Data Set) • Types • Integer (int) ; real numbers (float); Boolean (bool) • Operations (Data Manipulation) • Types • Addition (+); Assignment (=); Comparators (< > ==) • Statements (Determines Program Control) • Types • Loops (for, while); Decisions (if, switch); Declarative (continue, return) • Preprocessor Directives • Types • Definitions (#define); Include (#include)

  4. C++ • Review of new C++11 Features • Templates no longer have to be closed with space b/t close template expressions • Null point type • Automatic Type Deduction • Uniform initialization • For Loop Changes • Move Semantics • String Literals • No exception • Constant Expressions • New Template Features • Lambdas • Declaration Types • New Function Declarations • Scoped Enumerations

  5. C++ For loop changes Range-based for loops similar to shell programming for (inti : {1,2,4,16,256}) { do something } OR #define OK 0 Uniform initmap<string,string> myMap { {“ip”,”10.10.10.10”},{“brd”,”10.10.10.255”},{“ip”,”192.168.0.1”},{“brd”,””}} for (auto& i : myMap)  Automatic Type deduction { if(i[“ip”].compare(“192.168.0.1”) == OK) { do something here …. } }

  6. C++ Move Semantics What’s it good for? Efficiency of not having to make an expensive copy. The move will merely copies the reference of the thing in memory to a target location. #include <iostream> #include <utility> #include <vector> #include <string> std::string str = "Hello"; std::vector<std::string> v; v.push_back(str);  Place “Hello” in the first place of the vector, it is copied. v.push_back(std::move(str));  move the reference into the second place in the vector. What happened to str?

  7. C++ New Template Features • Variadic Templates • Aliased Templates • Default Template and local types arguments Variadic template <size_t… things> struct ArrayOfThings { size_t theArray[] = { things… }; } Aliased Template #include<iostream> #include<bitset> template <typename T> using strAlias= std::map< std::string, T >; EnummyBits {zero,one,two,three}; strAlias<bitset<4>> bitString; bitString[“first”].set(zero) ; bitString[“BitArray”].set(zero); bitString[“second”].set(one); bitString[“BitArray”].set(one); Default Argument Template <typename T, typename container = vector<T>>; class DefVector DefVector<int> Vec;

  8. C++ Lambdas Inline Expressions A method in which an anonymous function can be defined. These are of the form [capture](parameters)->(type){body}. A bit more powerful than creating MACRO s in C. [ ](int x, int y) { return x + y; }  Implicit return [ ](int x, int y) ->(int){ return x + y; }  Explicit return [ ]{ ++x; }  No parameters Closures A lambda function can refer to identifiers/parameters declared outside the lambda function. Closures are defined between the brackets [ ] of lambda expressions. [] //no variables defined. Attempting to use any external variables in the lambda is an error. [x, &y] //x is captured by value, y is captured by reference [&] //any external variable is implicitly captured by reference if used [=] //any external variable is implicitly captured by value if used [&, x] //x is explicitly captured by value. Other variables will be captured by reference [=, &z] //z is explicitly captured by reference. Other variables will be captured by value

  9. C++ • Utilities • Smart Pointers • Pairs and Tuples • Type Traits and Type Utilities • Clocks and Timers • Miscellaneous C Functions

  10. C++ • Lab Notes Cygwin on the PC provides • GNU compiler • Editors like vi and emacs • Gnu debugger • Terminal emulation such as xterm for vt100. • Python and bash shell languages and scripting. • SVN client access GNU Compiler (4.5.3) • g++ -v  returns the g++ version • g++ -std=gnu++0x  applies support for C++11 SVN (http://www.computerarcheology.com/cpp) • svn co http://www.computerarcheology.com/cpp • cpp  advanced  docs  sources

More Related