I am a C++ learner... I created a simple program wherein I created a constructor and two functions.. my problem is when I create an object and call a function the constructor is not called (edit:solved!).. also how can i call the add function with read function( so that after taking input from the user the program calls the add function and adds the numbers?)
edit:solved! constructor now works as intended, figured how to make another function call :)
#include<iostream>
using namespace std;
class class1
{
int x,y;
public:
class1()
{
cout<<"object created\n";
}
void read()
{
cout<<"enter x";
cin>>x;
cout<<"enter y";
cin>>y;
}
int add(int a, int b) //int add()
{
int sum=a+b; // int sum=x+y
cout<<"\nsum=" << sum; // return sum
}
};
int main()
{
class1 obj1;
obj1.read();
onj1.add(); //this was missing and it didnt work prevuiously
}