Struct and class similarities and differences

struct c is used when the language used to define the structure 

When the class is used to define the class in c ++

the same

struct (structure) and the class (class) can have different numbers, different types of data 

Struct or class must add the definition of the front

After the braces need to add a semicolon

difference

struct (structure) may be typedef short, may be a series of data recording, the array can be used to record a plurality of linked list

class (class) may also be defined based on a function, and is divided into public (public), private (private), protected (protected) three parts

When the definition data from other functions  

struct (structure)

If the struct (structure) using typedef not required for such abbreviations are as defined struct name structure name data; if this definition can be used for short data name;

class (class)

Class name data name; and upon the definition of such parameters may be transmitted directly class name A (1,2);

 

 

 

 

Guess you like

Origin www.cnblogs.com/wang9624/p/11979416.html