C++中给static变量赋值和返回



class PointA {
    
public:
    void show()
    {
        std::cout<<"PointA"<<std::endl;
    }
    
    
};
class  Point
{
public:
    static int temp ;
    static PointA point;
    
     
     int output()
    {
        return  temp;
    }
     static PointA init()
    {
        return point;
        
    }
};
//这样赋值
   int Point::temp = 30;
PointA Point::point = *new PointA();


int main(int argc, const char * argv[])
{

 
    
    Point pt;
   
    
    PointA pA =  pt.init();
    pA.show();
    
   int temp =   pt.output();
    std::cout<<temp<<std::endl;
    return 0;
}


你可能感兴趣的:(C++,static)