#include <iostream>
#include <windows.h>
#include <string>
usingnamespace std;
class addClass{
public:
void setInt (int x)
{
add2 = x;
}
int getInt(){
return add2;
}
private:
int add2 (int a,int b)
{
int ans = a + b;
cin >> a;
cin >> b;
ans = a + b;
return ans;
}
};
int main()
{
addClass addOB;
addOB.setInt(0,0);
cout << addOb.getInt();
system ("Pause");
return 0;
}
can anyone tell what im missing to make this private/ public class transfer properly? is there a specific "set/get" definition i need to know for dealing with integers/numbers?
setInt takes one argument so passing two arguments as you do on line 34 is an error.
Inside setInt you assign a value to add2. add2 is a function so that doesn't make sense. If you want the class to have a member variable named add2 you have to add it to the class definition.
1 2 3 4 5 6
class addClass
{
...
int add2;
...
};
You can't have a member variable with the same name as a member function so if you do with you will have to rename or remove the add2 function.