C ++ learning structure and a structure

Structure belongs to one of C and C ++ distinction.

Code examples are as follows (from "C ++ Programming Design"):

#include <the iostream> 
#include < String >
 the using  namespace STD;
 // structure 
struct EnemySpaceShip 
{ 
    int x_coordinate;
     int y_coordinate;
     int Power; 
};           // rear body structure always have to have a ';' 
 // structure initialization 
getNewEnemy EnemySpaceShip () 
 { 
     EnemySpaceShip Ship; 
     ship.x_coordinate = 0 ; 
     ship.y_coordinate = 0 ; 
     ship.power = . 4 ;
      return ship;
 }
 EnemySpaceShip upgrateWeapons (EnemySpaceShip ship)
 {
     ship.power+=10;
     return ship;
     return ship;
 }
 
int main()
{
    EnemySpaceShip enemy=getNewEnemy();
    enemy=upgrateWeapons(enemy);
    enemy=upgrateWeapons(enemy);
    cout<<"the ship is "<<enemy.x_coordinate<<","<<enemy.y_coordinate<<","<<enemy.power<<endl;
}

Guess you like

Origin www.cnblogs.com/fantianliang/p/11620328.html