In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the objects of C++ and the problems of inheritance and use", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn what are the problems of C++ objects and inheritance and use.
Define the abstract class class Person {public: virtual void born () = 0;}; inherit class Man of the class: public Person {public: void born () {cout study (); when defining the class, the attribute needs to be assigned an initial value if class StudentId {private: static StudentId* si; / / must be decorated with static / / must be decorated with static}; string StudentId::id = "20200001" StudentId* StudentId::si = pre-declaration of the NULL; class
Before C++ uses this class, it must be defined, otherwise the compiler will not know it exists.
Therefore, when two classes are nested within each other, an error may be reported, and the solution is to use the pre-declaration
If the relevant methods of another class are used in the method implementation of the class
Then it is best to write the definition and implementation of class methods separately.
The pre-declaration of the class AbstractChatroom; / / class class Member {protected: AbstractChatroom * chatroom; / / you must define the void setChatroom (AbstractChatroom * chatroom) {/ / the class method can implement this- > chatroom = chatroom;} void chatroom_play () when the class is defined; / / when the method inside the method needs to be used in the pre-declaration class, it can only be defined first and then implemented} Specific definition of class AbstractChatroom {/ / class public: mutual nesting of Member member; / / classes virtual void sendText (string from,string to,string message) = 0; void play () {cout name = name; this-> age = age; this-> home = home;} string Student::getName () {return name;} int Student::getAge () {return age;} string Student::getHome () {return home } void Student::setName (string name) {this-> name = name;} void Student::setAge (int age) {this-> age = age;} void Student::setHome (string home) {this-> home = home;}} / / use the namespace, method 1using namespace my_namespace;int main () {Student * stu1 = new Student ("Zhang San", 18, "Beijing"); cout getName ()
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.