Class member invocation in "record" C + +

Source: Internet
Author: User

The code is as follows:

file contains and preprocessing. CPP: The entry point that defines the console application. #include "stdafx.h" #include <string> #include <stdio.h> #include <windows.h> #include <iostream >using namespace Std;class fruit{public:fruit (const string Nst,const string cst): Name (NST), colour (CST) {}void print ( {cout << name << endl;cout << colour << Endl;} void Ck (int i) {for (; i <; i++) {printf ("%d", I);}} Private:string name;const string colour;}; int _tmain (int argc, _tchar* argv[]) {Fruit Apple = fruit ("A", "1"); Fruit orange = fruit ("B", "2"); Apple.print (); orange.pri NT (); Fruit a=a;a.ck (6); GetChar (); return 0;}

Public function in the class member, here I declare a CK function name

A For loop is nested inside, and when called, the class initialization object calls the CK

It is not possible to call directly through the class name, which differs from C in that it initializes an object to invoke.

Fruit a=a; This piece of online has many kinds of explanations, finally see the disassembly is not a hint, anyway can call out on the line.

Leave a picture. :

Class member invocation in "record" C + +

Related Article

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.