constructorsclass内一类特别的memberfunction其特性.pptVIP

  • 2
  • 0
  • 约8千字
  • 约 18页
  • 2018-05-10 发布于天津
  • 举报

constructorsclass内一类特别的memberfunction其特性.ppt

constructorsclass内一类特别的memberfunction其特性

C++ Overview 1999 amendment to c99 C with class Important concepts of C++ Function overload: different function using same function name. Enhance struct ? class (accept as a new type) Three access levels, (define friends of the class) Constructors (with function overload), Allow functions to be class members, Adopt operator as a class member function, Inheritance (layered) class structure. Implicit function overlaod: template. Use namespace: prefix to functions and classes. Function pass by reference (additional to value address) Using namespace old compiler #include iostream.h New compiler #include iostream; using namespace std; In headfile iostream is written as: namespace std { …. } all functions and classes are prefixed with “std::”, std::cin, std::cout.. specify the using namespace to omit the prefix. namespace namespace std { class iostream cout; …..; } defined in iostream #include iostream; std::cout “test\n”; #include iostream; using namespace std; cout “test\n”; Function overload (example) c++ can distinguish functions of same function name by their arguments (if distinguishable). Same function name with indistinguishable arguments ? compiler error. Class – an object members and member functions (ex) New features of class Member function 使用 member function Constructor (example) Constructors -- 在創造 class 物件時, 賦與某些 data 的值 名字和 class 名字相同. 不須 function type, 也不須 return 的指令. 可以許多 constructor, 原則與 function overload 的原則相同. Write a polynomial class 練習九:把 newton 法的多項式改用 class 寫法. Operator 是否必須宣告為 friend? * * OOP: “object oriented programming” refers to structure of class. “Stream i/o” is a C++ class. class quadratic { private: // access leve: public, protect, private double a, b, c; // class members // class member functions public: void setcoef (double r1, double r2, double r3); double value(double

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档