hi
i tried this prog on classes but its having an error in line as mentioned below
help me figure it out
/*1. Make a class called "point" with two integer data members x and
y. Show how to create and use two points p1 and p2.*/
#include <iostream>
using namespace std;
class point
{
public:
int x;
int y;
int sum(int,int);
};
int point::sum(int a,int b)
{
cout << "enter any 2 integers";
cin >> a >> b;
x = a;
y = b;
return(x+y);
}
int main()
{
int s;
point D;
s = D.sum(int a,int b); //this line has error
cout<<s;
return 0;
}
plz help
~
int point::sum(int a,int b);
this means that you should give two values at the function.
s = D.sum(int a,int b);
should be written like this:
s = D.sum(a,b);
where
a and
b were previously declared.
In the way you are using
a and
b in
point::sum()
, I suggest to modify it in this way:
1 2 3 4 5 6
|
int point::sum()
{
cout << "enter any 2 integers";
cin >> x >> y;
return(x+y);
}
|
so You can call the function without any argument:
s = D.sum();
Last edited on