Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top