tailieunhanh - Object oriented programming with C++ - Session 2 More on Classes
Use the scope resolution operator Use dynamic memory allocation with New Delete Use pointers to objects Define and use Constructors Define and use Destructors Define the "Const" keyword Define and use the "this" pointer Describe how objects and functions are arranged in memory Static Data Members Static member Functions Describe type conversions using Converting by assignment Type casting | More on Classes Session 2 Session Objectives Use the scope resolution operator Use dynamic memory allocation with New Delete Use pointers to objects Define and use Constructors Define and use Destructors Define the "Const" keyword Object Oriented Programming with C++/ Session 2/ of 37 Session Objectives (Contd.) Define and use the "this" pointer Describe how objects and functions are arranged in memory Static Data Members Static member Functions Describe type conversions using Converting by assignment Type casting Object Oriented Programming with C++/ Session 2/ of 37 Scope resolution operator Function can be defined outside the class specifier using a scope resolution operator :: (double colon symbol) with the function definition. . General syntax: return_type class_name ::member_functions(arg1, arg2,. . .,argn) The type of member function arguments must exactly match with the type declared in the class specifier. Important for defining the member functions outside the class | More on Classes Session 2 Session Objectives Use the scope resolution operator Use dynamic memory allocation with New Delete Use pointers to objects Define and use Constructors Define and use Destructors Define the "Const" keyword Object Oriented Programming with C++/ Session 2/ of 37 Session Objectives (Contd.) Define and use the "this" pointer Describe how objects and functions are arranged in memory Static Data Members Static member Functions Describe type conversions using Converting by assignment Type casting Object Oriented Programming with C++/ Session 2/ of 37 Scope resolution operator Function can be defined outside the class specifier using a scope resolution operator :: (double colon symbol) with the function definition. . General syntax: return_type class_name ::member_functions(arg1, arg2,. . .,argn) The type of member function arguments must exactly match with the type declared in the class specifier. Important for defining the member functions outside the class declaration. Object Oriented Programming with C++/ Session 2/ of 37 Scope resolution operator (Contd.) The left-hand operator of :: must be the name of the class. Only the scope operator identifies the function as a member of a particular class. Is also used to refer to global variable names in cases where a global variable and a local variable share the same name. The syntax used is: ::global_variable More freedom in naming variables. If two variables have different purposes, their names should reflect the difference. Object Oriented Programming with C++/ Session 2/ of 37 Dynamic memory allocation An object is created when its definition appears in a program and it is destroyed when its name goes out of scope or the program terminates. Useful to create a new object that will exist only as long as it is needed. new creates such objects and the operator delete can be used to destroy them later. Objects allocated by new and delete are said to be on the free store. Object .
đang nạp các trang xem trước