Zero-based colleagues to learn C ++ and self-month summary of some two weeks after the java class

C ++ and java is syntactically similar

Output statement C ++: cout <<

Output statement java: System.out.print ()

Both contrast C ++ is more concise, although sout java can be used to quickly finish up output statement but still bloated when read.

Enter the statement C ++: cin >> or getline (cin, content)

Enter the statement java: Scanner input = new Scanner (System.in) // create an object and then input variable assignment

When comparing the two C ++ Either way is better than the java, java first when writing code can be found there is no multiple input operations by line of code case

Each use will need to deal with multiple statements coherent input multiple times, such as C ++ input name, age, gender, etc. may be used:

cin >> name >> age >> gender; such an assignment to a statement multiple times

The java need:

First you need to create the output object Scanner

Then an object is assigned one by one, and needs to be determined according to the type of data mura crude

name=input.next();

age=input.nextInt();

gender=input.next().charAt(0);

When comparing the two java still reflects the increasing amount of codes, (probably due to java properties as fully object-oriented language, said they did not understand this, but whether C ++ or JAVA here should all use the older cattle people leaving facilities)

These are the basic input output target contrast, can not talk about understanding can only say that you can use.

type of data

C ++ int shortint longint longlong float double longdouble char bool (because there is no real experienced any project or practice. Specific use for a wide character and just take the positive part of the data types do not understand)

Eight basic data types java byte int short long float double char boolean

Comparison between the two seems the difference is not too great, I understand the following points

First, the simplest type bool in C ++ is shaped storage can be easily converted to 1s and 0s, and the java as a single type of storage, although it may be represented by 1 and 0, but bool types of data java and can not be directly converted.

Therefore C ++ bool type look slightly flexible.

Followed by a long plastic part, although I have contacted all the data are sufficient to cope with the int, but should deal with the situation of huge data, C ++ provides longlong type, scope is broader than the scope of java village crude.

Other due in part to byte no contact not know, c ++ and java are basically a float personal use double substitution, for the time being unknown differences between these two will produce in terms of efficiency, it just double easier to use.

* Float and double standard wording: 1.1f, 1.2d. Generally omitted defaults to double.

Special types of string:

On the current study to see whether it in C ++ or java string in string type is a special type. This type of foundation is of type char array of characters.

Thus extraction operation can be carried out in java in C ++ and its individual elements

c ++ does not learn to operate on the string, personal guess probably because c ++ string being built in the former more perfect

Capitalize in JAVA string of S and C ++, the same as other basic types can be

c ++ strings need to import operation #include <string>

import java indication is not required, since he is present in the java.util. * package base which, java-based content is not required to manually package introduction is introduced default

But C ++ namespace If you need to call these functions require the header file and import. (PS: namespace part do not understand, though every STD call but did not know its internal structure)

The three control structures if switch for, when using both feel little difference.

About functions:

C ++ is a function of the argument, which is the method java.

C ++ functions can exist in separate, even create a separate template function to facilitate the call

定义:template<typname T&>void swap<t&,t&>

Function templates and template definition consists of a function definition, function, and function declarations templates together, usually on one line, generally in place of the data type T

Description: template // This declaration is a template

          typname // type name

          T & // parameter of type 

The role of template functions, when defining variables and functions are required to implement the use of reference.

Personal understanding part: Quote as reference-body referenced objects in C ++. Template function is a data type of the referenced determination from the body.

Function overloading part

Function overloading not much content, personal understanding is that the compiler a similar function names + data type + data types. . . . The way to rename

Example: void func (string) and the void func (int) is similar to rename func_string compiled and func_int, and therefore can not function also led to the presence of two functions with the same name and the same parameters in the reload

***********************************************************************************************************************************************************************************************

OOP part

Classes and Objects

C ++ function corresponding to part of a method of classes and objects.

After collectively referred to as method

+ Class attribute is made of a method.

Property is a static object having a feature, the method is operable object's behavior.

Is an abstract class (here does not mean an abstract class, an abstract herein refers to fuzzy rather than 'pumping' 'like')

Objects are instances of classes, which is a clear individual.

Create a class distinction in the creation of the

java class name need to use object name (variable name) = new class name ();

c ++ There are two ways (both need to import the file header, and the header file is a self-defined because it is necessary to '' to guide but not official <>)

Method 1: Type Name Object Name;

(Personal understanding: an object created by this method is in the stack area.)

Method 2: * type name (type name pointer) type name = new object name;

First, new means of dynamic memory allocation, this time generated objects allocated in the heap area

The difference here is that java runs on the jvm, because it is a virtual machine is therefore very safe and java have automatic memory recovery mechanism, although personally do not understand.

C ++ memory manually assigned using the new release. So when we must use new with delete delete. If you can not delete the risk of memory overflow

This does not appear in java, but there has been deleted due to the characteristics and in some cases will be more flexible.

Access modifiers:

public access to public owner

private classes can access this private

protected protection of the present packages and subclasses can access

This friend does not write it in java for the default access modifiers, can be accessed in this package, but C ++ is private by default

Although there are c ++ friend, but I have not learned to record in the future.

Create a property:

java currently need access modifiers are added in front of each property

c ++ only need access modifiers: default to the following area for the same type of access modifiers

Creation Method:

java as a fully object-oriented language, can be implemented directly in the class

Only as a C ++ class definitions and attribute method, a method implemented in the class but not implemented in other documents CPP

The problem here is that if the class would meet the definition of property is private, needs to be exposed in other ways it is intended for use when implemented in other CPP files.

(Personal understanding part: C ++ inline functions exist will become inline function if the function is implemented directly namename call in the class, inline function directly copy the code to compile-time equivalent although the function call can be realized at, but the long code. efficiency is not high)

Temporarily write to you

Guess you like

Origin www.cnblogs.com/deemohans/p/11665828.html