0
What went wrong here? Pls help
2 Answers
+ 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;
}
+ 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.