Politechnika Śląska - strona 147

note /search

Matching overloaded functions

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

Matching overloaded functions  no more than one conversion per argument  pick lowest match level, ambiguity is an error 1. exact match (no conversion, but table to pointer, function to pointer...

Memory management

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

Memory management  allocating memory: operator new  syntax: new Type  example: int * pi = new int; // in C: pi = (int*)malloc(sizeof(int))  deallocating: operator delete  syntax: delete pointe...

Operators

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

Operators  What is an operator a = b.val 4 + c * d[ e++ ]  operator defines operations performed on its arguments and the type of the resulting expression - similarly to functions  in C++, we may define operators to be used with objects (at least one argument of the operator should be an object...

Order of calling constructors and Destructors

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

Order of calling constructors and Destructors  Constructors 1. base class (classes in order of declaration) 2. class members in order of declaration 3. constructor's body  Destructors - simply opposite order 1. destructor's body 2. destructors of class members (order opposite to declaration) 3. d...

Overloaded functions

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

Overloaded functions  More than one function of the same name, … but different parameters  Type of result is irrelevant (may not be used to overload) … because the result may be ignored in the call int f(int, int); int f(int); int f(long);  Pointers to overloaded functions - the compiler has to ...

Problems with References

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

Problems with References  Problems: - when the actual parameter type is not the same as formal - … or is an expression: char c=1, int a=2, int b=3; swap(a, c); swap(a+1, b);  arguments are converted to const (const int), compiler expects int (not const)  it should exit with error, usually issues...

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 ...