Deep Exploration C ++ object model Reading Notes (3 ).
Test the following code in Visual C ++ 6.0:
#include "iostream"using namespace std;
class X {};class Y : public virtual X {};class Z : public virtual X {};class A : public Y,public Z {};
int
If A class only defines the class name and does not define any methods or fields, such as class A {}; then each instance of class A occupies 1 byte of memory, the compiler inserts A char in this instance to ensure that each A instance has a unique
1. Static members(1) modified by the keyword staticThe static variable definition statement is executed at the compilation stage and no longer executed during the running process.(2) classification: static data members and static member functions.(3)
Static class member usage
# Include using namespace STD; class base {public: Base (int I): B (I) {} static int get_a () {return a;} PRIVATE: int B; static int A; // static const int A = 5 ;}; int base: A = 5; // int base: B = 6; // errorint main ()
Mutable is an uncommon keyword in C ++. It can only be used for non-static and non-constant data members of a class.We know that the state of an object is determined by the non-static data member of the object. As the data member changes,The status
The static keyword is a keyword that exists in both C and C ++. It mainly has three usage methods. The first two are only used in C, the third method is used in C ++. (The detailed operations in C and C ++ vary. This document uses C ++ as the
Summary of C static usage
The static keyword is a keyword that exists in both C and C ++. It mainly has three usage methods. The first two are only used in C, the third method is used in C ++. (The detailed operations in C and C ++ vary. This
1: first look at the size of an empty class:
#include using namespace std;class A{}; int main(int argc, char** argv) {cout
The result of sizeof (a) is 1;
#include using namespace std;class A{public:A();~A();}; int main(int argc, char** argv)
1. The first and most important article is to introduce it: hide . (static function, static variable all available)When multiple files are compiled at the same time, all global variables and functions that do not have a static prefix have global
static data member/member functions in C + + represent variables and functions that belong to a class and not to any particular object of this class. This is the biggest difference from the normal member function, and also its application, such as
Summary of static keyword function in C + +1. The first and most important article is to introduce it: hide. (static function, static variable all available)When multiple files are compiled at the same time, all global variables and functions that
12th Chapter Category
Each class can have no members, or it can define multiple members, which can be data, functions, or type aliases.
member functions must be declared inside a class, can be defined inside a class, or can be defined outside
Using the static modifier to declare static members that belong to the type itself, rather than to a particular object, can be used for classes, fields, methods, properties, operators, events, and constructors, but not for indexers, destructors, or
"Absolute C + +"
Constructors and other Tools--------------------------------------------------------------------------------------------------------------- ------------TIP1: The constructor cannot be called as a member function, nor does it
When choosing a programming specification, I preferred Google, followed by Huawei and Microsoft, and finally adjusted according to some of its own realities. The following is an excerpt from Google's C + + programming specifications.—————————————————
There are three main functions of static:
(1) Local static variables
(2) External static variable/function (3) static data member/member function
The first two kinds of C and C + + have, the third is only in C + +, the following are described below:
Programmer Sutra Pavilion---C + + programming Bingshu
static member class: Easy to be shared by all objects of class;
static data member static int A: Creates and initializes a-------------only once the program starts executing (contrast: non-static
Some things you use every day, but not necessarily on behalf of you really understand it, as I have known before the static. one, static class
The important difference between a static class and a Non-static class is that a static class cannot be
If you want a member of a class to be able to share all of the class objects, you can use static members to implement them.Use the example in the book to define an account class that represents the accounts in which a InterestRate member represents
12th Chapter Class
1 data abstraction is a programming (and design) technology that relies on interface and implementation separation. Encapsulation is a technique that combines low-level elements to form new, high-level entities.
2 the only chance
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.