Computer Programming - strona 3

note /search

Relationships between C and C++

  • Politechnika Śląska
  • Computer Programming
Pobrań: 14
Wyświetleń: 924

Relationships between C and C++  C is almost a subset of C++  You may add only some elements of C++ to your C program  C++ overhead is not incurred unless you explicitly ask for it - it's still possible to write small, fast code  C++ is stricter: C warnings are usually errors in C++ ...

Standard input and output

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 385

Standard input and output  We may still use C functions (printf etc.)  We should use C++ operators  Do not mix them! #include using namespace std; ... int a,b,c,d; cout a; cin b; cout c d;  Streams are more fault-tolerant than functions ...

Static class members

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 518

Static class members  a static class member is shared by all the class objects  static members exist even if there are no objects of the class  we may access it using the scope operator class ST { static int s; // declaration only int i; public: static int ps; // as above }; int ST::s=0, // defi...

Static methods

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 455

Static methods  may be invoked even if there are no objects (using the scope operator)  may access static class variables and static methods only  there is no ”this” in static methods class ST { static int s; int i; public: static int ps; ST(int i=0) :i(i) { s++; } static void count_us() { cout ...

Stream operators

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 497

Stream operators  Input friend istream & operator (istream &, T &);  Output friend ostream &operator (istream & s, point & p); friend ostream &operator p; cinpp2; cout p.x p.y; return s; } ostream &operator ...

The scope operator as a non-OO C++ extension

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 315

The scope operator as a non-OO C++ extension int fun(); int i; class C { int i; public: void test(); int fun(); }; void C::test() { i++; // C::i++ ::i++; // global i fun(); // C::fun() ::fun(); // global fun() } ...

Variable function argument list

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 399

Variable function argument list  in C we write: int printf(char *, …);  in C++ a bit simpler: int printf(char * …); // comma not required, but only if // variable preceding ”…” has no default value. // Macros for accessing args in (like in C)  ...

Books on C++

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 882

Books on C++  Bjarne Stroustrup „Język C++”, WNT  International Standard for Information Systems - Programming Language C++ (draft), ANSI  Stroustrup B.: Projektowanie i rozwój języka C++. WNT, Warszawa  Plauger P. J., Biblioteka sta...

Calling

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 511

Calling We may specify which one to call: point p3=point(10.0, 20.0); point p2=point(1.0); point p1=point(); or: point p3=point::point(10.0, 20.0); point p3=point::point(1.0); point p1=point::point();  anonymous objects point pu; // non-anonymous object pu pu = point (3); // temporary anonymous ob...

Compiler generated copy constructor

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 427

Compiler generated copy constructor  if programmer does not define a copy constructor - the compiler generates one  other constructors are not important in this case  compiler generated copy constructor copies object field by field - base classes and object members with their copy constructors -...