0
Substract
How a class function can access another member of a class Example: class otherthing{ }; class somthing{ Public: Int waka=1000; }; class another:public otherthing{ Public: Int chapa=100; Void patanga() { waka=waka-chapa; } }; Int main () { another a; otherthing *p1=&a; p1->patanga(); } What's the problem?
3 Respostas
0
What do you want to do?
And where have you declared a class otherthing?
0
Substract those two
0
#include <iostream>
using namespace std;
class somthing{
public:
int waka=1000;
};
class another:public somthing {
public:
int chapa=100;
int patanga() {
waka=waka-chapa;
return waka;
}
};
int main() {
another a;
another* p1=&a;
cout << p1->patanga();
return 0;
}
This works.
You created class otherthing for no reason and you tried to inherit from it. Above all that you tried to create a pointer of that. Please try to understand everything you write. I am saying that because your variable waka was in class somthing and that is the reason you couldn't subtract things.