C ++ _ 01 _ getting started, _ 01 getting started
I. Class Definition Person. h class declaration
Person. cpp class implementation
Main. cpp main Function
Ii. namespace usage
Xcode format code: ctrl + I
Main function:
Iii. class inheritance parent class Person
Subclass Girl
Key settings for using extends in Java PHP
Colons in c ++ indicate inheritance, which is the same as Objective-C.
Public after the colon (:) indicates that the inherited Dongdong public
Main function main. cpp
Iv. Object Construction and destructor
Main. cpp main Function
5. Execute parent class
Of 【Constructor]Parent class Person
Subclass Girl
// Call the constructor of the parent class. cpp is implemented by a colon.
// In Java and Objective-C, the super keyword is used.
// Use the parent keyword in PHP
Main. cpp main Function
6. Call the method C ++ of the parent class without the super keyword. Therefore, call the method of a parent class through [parent class name: method ()].
C ++ can also specify the parent class method to call.
// Because c ++ does not have the super keyword, the method used to call the parent class is [parent class name: method ()]
// The advantage is that, no matter how much inheritance is involved, you can use the parent class name to specify the method for calling a parent class at a certain level;
Therefore, it is more powerful than the super keyword in Java.
Parent class Person
Subclass Girl
VII. Real Functions, virtual functions, pure virtual functions, and function Overloading
In C ++, because both the parent class and subclass implement the cry method [real function ],
Therefore, only the cry method of the parent class is called.
If you want to implement polymorphism in Java,
The cry method of the [parent class and subclass] must be declared as a [virtual function] with the virtual keyword]
In addition, C ++ pure virtual functions, similar to abstract methods in Java, are implemented by different subclasses.
Parent class Person
Subclass Girl
Main. cpp main function when both the parent class and subclass implement the [real function cry]: directly call the cry of the parent class
When the cryy methods of the parent class and subclass are declared with the [virtual] keyword, the method of the subclass is called like the Java polymorphism.
Pure virtual Method
// Pure virtual functions, similar to abstract methods in Java, implemented by different subclasses
Virtual void holobby () = 0;
8. Classes in C ++. If all the methods are pure virtual functions, they are pure virtual classes. They are equivalent to interfaces in Java. Because C ++ itself supports multiple inheritance, in use, try to follow the Java [single inheritance to implement multi-interface principle] and design other parent classes into pure virtual classes. IX. Function overload, that is, the name is the same, you do not need to add * For the string types of different C ++ parameters *
10. Operator Overloading
// Overload + = Operator
Voidoperator + = (Point other ){
Add (other );
};
Return Value operator (parameter list ){};
Access through an object instance (or struct) and use the [.] pointer to access using the [->] Point class
Main function main. cpp
Use Pointer,->, to unreference
11. pseudofunctions are called like functions, but not functions. In essence, they are class or struct. Benefits: some code segments can be passed as an object instance of a class. For example: as a method callback,
C ++ references]
Avoid unnecessary memory copy operations
14. Role of the C ++ youyuan class: publish the private Members in the class to a specific class [youyuan class] because it is not very easy to manipulate, so, java language does not have this concept in C ++. The default access modifier is: pravite [use the keyword friend class Foo in class A;] declare A friend class, the Foo class can access the private members in Class A (the coupling degree is too high)
17. Right-click "products" in "show in finder" to view the output file. Use ofstreamto output to file 1.txt.
Use ifstreamto read 1.txt in the debugdirectory
Use ifstreamto read 1.txt in the debugdirectory
The stringbuf class represents the buffer. It is defined in the header file <sstream>.
<Span style = "font-size: 14px;"> /// main. cpp // 17 _ file operations /// Created by beyond on 14-10-2. // Copyright (c) 2014 com. beyond. all rights reserved. // # include <iostream> // introduce the header file fstrem, that is, the file stream # include <fstream> // use the stringbuf Character Buffer # include <sstream> using namespace std; void testOutput () {// correlation 1.txt ofstream stream ("1.txt"); stream <" Hello Beyond "; // remember to close the stream at last. close (); std: cout <"\ n> end output <\ n";} void testReadOneChar () {// use the input stream ifstream input ("1.txt"); // cache char c; input> c; // remember to close the stream input. close (); printf ("% c", c);} void testReadToConsole () {// use the input stream ifstream input ("1.txt"); // cache stringbuf buf; // read the buffer input >>& buf; // remember to close the stream input. close (); std: cout <buf. str () <"\ n> end <\ n";} int main (int argc, const char * argv []) {// testOutput (); // testReadOneChar (); testReadToConsole (); return 0 ;}</span>
16. C ++ string
The C ++ string is packaged into a string class; the operator + = is overloaded and can only receive strings.
After importing <sstream>, you can use the stringstream class.
It can connect different types of variables,
Because it overload the operator <
Therefore, different types can be connected.
And the returned value is stream itself. Therefore, it can be continuous <
Call the str () method to return the c ++ string.
Continue to call the c_str () method and return the C string
Online address of C ++ API Parameters
C_str () method of the string class
Stringstream class
Str () method of the stringstream class
C language basics
Advanced embedded advanced C Language
C language overview-01C concept, development history, and features
C language overview-basic program structure of 02C
C language overview-2nd programs in 03C language 3rd programs
C language overview-04C Program Development Process
C language overview-Analysis of Common Errors in 05C Language Development
C language overview-Relationship between 06C language development language and development tools
C Programming basics-Basic Data Types of 01C Language
C Programming basics-02 constants and variables
C Programming basics-03const type modifier Concept
2C programming basics-03const type modifier instance
C Programming basics-04volatile type Modifier
C Programming basics-05 extern, static storage
C Programming basics-06register storage type specifier
C Programming basics-07auto storage type specifiers
C Programming basics-08 operators-Arithmetic Operators
C Programming basics-09 operator-sizeof Operator
C Programming basics-09 operator-relational logic operator
C Programming basics-09 operator-bitwise Operator
C Programming basics-10 expressions
C Programming basics-11if condition judgment Structure
C Programming basics-12switch condition judgment Structure
C Programming basics-13for Loop Structure
C Programming basics-14while Loop Structure
C Programming basics-15 jump statements
C Programming basics-16 Modular Design Method
C Programming basics-17 description and definition of functions
C Programming basics-18 function calls
C Programming basics-19 recursive functions
C Programming basics-20 function return values
C programming advanced-1 Array
C programming advanced-1 string
C programming advanced-3 pointer
C Programming (advanced tutorial)-4 function pointer
C programming advanced-5 dynamic type allocation
C programming advanced-6 pointer Common Errors
Advanced C Programming-7 pointers and Arrays
C programming advanced-8 Compilation preprocessing
C Programming-9 Structure Basics
C programming advanced-10 linked list
C Programming-11 sharing
C Programming-12-bit advanced Section
C programming advanced-13 Enumeration
C programming advanced-14 files
C Programming Summary
A c language entry book is recommended.
Of course it's a classic Wrox Redbook.
C language entry classic