[SOLVED] How to write the constructor for this c++ code?

Status
Not open for further replies.

rahul.6sept

Full Member level 5
Joined
Nov 17, 2006
Messages
243
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
Guwahati, India
Activity points
2,889
Dear all,

How shall I write the constructor for this code so that it runs?


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
class A {
const int id;
public:
   A (int num):id(num)   //constructor
                                                            
void display() {
   cout << id;
   }
};
int main() {
   int val;
   cin >> val;
   A ob (val);
   ob.display();
   return 0;
}



only constructor can be modified. How can I do this so that input = output

Regards

- - - Updated - - -

I got the solution
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…