fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Car{
  5. //private:
  6. public:
  7. int number;
  8. int gas;
  9. Car(int n = 0, int g = 0){number = n; gas = g;} // Constractor
  10. static void showCarInfo(const Car& c);
  11. void show() const; // Member function
  12. };
  13.  
  14. int main(){
  15.  
  16. Car mycar(2, 4);
  17. Car::showCarInfo(mycar); // Okay
  18. mycar.show(); // Okay
  19. return 0;
  20. }
  21.  
  22. void Car::showCarInfo(const Car& c){
  23. cout<<"The car number is "<< c.number <<endl;
  24. cout<<"The gas is "<< c.gas <<".\n";
  25. }
  26. // Member function
  27. void Car::show() const {
  28. cout<<"The car number is "<< number <<endl;
  29. cout<<"The gas is "<< gas <<".\n";
  30. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
The car number is 2
The gas is 4.
The car number is 2
The gas is 4.