Advertisement
alfps

Untitled

Jun 12th, 2020
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A
  5. {
  6.     int m_a;
  7.  
  8. public:
  9.     A( const int x )
  10.         : m_a( x )
  11.     {}
  12.  
  13.     void display() const
  14.     {
  15.         cout<< "The value is " << m_a << "." << endl;
  16.     }
  17. };
  18.  
  19. int main()
  20. {
  21.     for( int i = 0; i < 2; ++i ) {
  22.         cout<<"Please enter value " << i + 1 << ": ";
  23.         int x;                          // <- The crucial fix.
  24.         cin >> x;                       // <- ... and here.
  25.         A obj( x );                     // <- ... and here.
  26.         obj.display();
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement