How access class variables in c++

前端 未结 4 1731
没有蜡笔的小新
没有蜡笔的小新 2021-01-20 00:44

Is it possible in c++ to access class variables in other classes without creating an object. I have tried to use static, but the other class doesnt recognize my variable. I

4条回答
  •  再見小時候
    2021-01-20 01:10

    yes you can bro, try this

    struct car{

            string model;
            string paint;
            int price;
    
    
               };
    
    
             int main(){
    
              // creates an object of the class car
    
                car BMW;
    
              // assign the values
               bmw.model = "m sports";
                bmw.paint ="red";
                bmw.price = 24000;
    
    
                  }
    

提交回复
热议问题