C ++ learning structures and Classes

Source: Internet
Author: User

It is said that in C ++C LanguageStructure that is retained.

Since the class in C ++ is the struct and function in C language. In this way, the struct in C ++ can also define functions.

The key to posting this blog is to review the classes in C ++. Today, I have been kneeling on the member attributes of the class for a long time. (Private, public, or something is completely forgotten)

Note: In the C ++ class, Private Members can only be accessed by public functions and cannot be accessed directly from variables of this type.

/* Subject: struct content in C ++: struct constructor, member function */# include <iostream> using namespace STD; the member types in struct triangle // struct are all public. {Int A, B, C; triangle () {}// constructor void getedge (INT X, int y, int Z) // member function of triangle {A = X; B = y; C = z;} void print () // triangle member function {cout <A <"" <B <"" <C <Endl ;}; int main () {triangle T; int x, y, z; CIN> x> Y> Z; T. getedge (x, y, z); T. print (); Return 0 ;}

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.