In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the UML constructor to initialize the object". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to initialize the object using the UML constructor".
Preliminary knowledge
Each class can provide a constructor for initialization when a class object is created. The constructor is a special member function that must be defined with the same name as the class so that the compiler can distinguish it from other member functions of the class. A major difference between constructors and other functions is that constructors cannot return values, so you cannot specify a return type for them. Normally, the constructor is declared as public. Exe.
The program is as follows: / / Instantiating multiple objects of the GradeBook class and using the GradeBook constructor to specify the course name / / when each GradeBook object is created.#include using std::cout; using std::endl;#include / / program uses C++ standard string classusing std::string;// GradeBook class definitionclass GradeBook {public: / / constructor initializes courseName with string supplied as argument GradeBook (string name) {setCourseName (name) / / call set function to initialize courseName} / / end GradeBook constructor / / function to set the course name void setCourseName (string name) {courseName = name; / / store the course name in the object} / / end function setCourseName / / function to get the course name string getCourseName () {return courseName / / return object's courseName} / / end function getCourseName / / display a welcome message to the GradeBook user void displayMessage () {/ / call getCourseName to get the courseName cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.