Use of the 7--c++ class

Source: Internet
Author: User

Once you have defined a class, you can create an object of that class just as you would declare a simple variable with a type of int, double, and so on, calledinstantiation of a class。 The definition of a class is actually defined as a type that the class does not receive or store specific values, only as a "blueprint" for generating concrete objects.The system allocates storage space for objects only after the class is instantiated and the object is created (a variable that declares the class).  
Computer.hclass Computer//class definition {  private:             char brand[20];            float price; Public:             void print ();             void Setbrand (const char * sz);             void Setprice (float PR); };  

  

#include "computer.h"//contains class definition #include <iostream>using namespace std;   void computer: Implementation of the:p rint ()//member function {             cout << branding: << brand << Endl;             cout << "Prices:" << price << Endl;  } void Computer::setbrand (char * sz) {             strcpy (brand, SZ);//String copy}  void Computer::setprice (float PR) {             price = PR; } #include "Computer.h"//defines class computer int main ()//main function {             computer COM1;//Declares Computer class object (or class variable) COM1 com1            . Setbrand ("Lenovo");//Call the public member function Setbrand set branding brand             com1. Setprice (8000); Call public member function Setprice set brand price             com1.print ();//Information output             return 0;}  

  

Use of the 7--c++ class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.