10th Aug 2021, 1:37 PM
Nihal Kumar Das
Nihal Kumar Das - avatar
2 Antworten
+ 6
You have to call cin within the constructor of the class (which you didn't define, and should) to initialize l, b , s, ie: class area { private: int l,b,s; //data member public:// access specifier area(); //constructor int rectangle(); //member function int square(); // declaration }; area::area(){ cin>>l>>b>>s; }
10th Aug 2021, 1:44 PM
BootInk
BootInk - avatar
+ 2
Adding to what BootInk said. Although it workes here, I would not recommend performing i/o in class methods ( especially constructor ). You would have a very hard time working with such design.
10th Aug 2021, 4:30 PM
Arsenic
Arsenic - avatar