tailieunhanh - Ivor Horton’s Beginning Visual C++ 2005 phần 5
định nghĩa, mã của bạn sẽ không biên dịch. Bạn đã nhìn thấy đoạn mã này đã, vì vậy tôi sẽ không thảo luận về nó một lần nữa. Nó sẽ là một ý tưởng tốt để lưu các tập tin tại thời điểm này bằng cách nhấn vào nút Save trên thanh công cụ. Nhận được vào các thói quen tiết kiệm các tập tin bạn đang chỉnh sửa trước | Chapter 8 definition your code will not compile. You ve seen this code already so I won t discuss it again. It would be a good idea to save the file at this point by clicking the Save toolbar button. Get into the habit of saving the file you re editing before you switch to something else. If you need to edit the constructor again you can get to it easily by either double-clicking its entry in the lower pane on the Class View tab or by selecting it from the right drop-down menu above the pane displaying the code. You can also get to a member function s definition in a .cpp file or to its declaration in a .h file directly by right-clicking its name in the Class View pane and selecting the appropriate item from the context menu that appears. Adding Function Members You need to add all the functions you saw earlier to the CBox class. Previously you defined several function members within the class definition so that these functions were automatically inline. You can achieve the same result by entering the code in the class definition for these functions manually or you can use the Add Member Function wizard. You might think that you can define each inline function in the .cpp file and add the keyword inline to the function definitions but the problem here is that inline functions end up not being real functions. Because the code from the body of each function has to be inserted directly at the position it is called the definitions of the functions need to be available when the file containing calls to the functions is compiled. If they re not you ll get linker errors and your program will not run. If you want member functions to be inline you must include the function definitions in the .h file for the class. They can be defined either within the class definition or immediately following it in the .h file. You should put any global inline functions you need into a .h file and include that file into any .cpp file that uses them. To add the GetHeight function as inline .
đang nạp các trang xem trước