Imagine I have a class and it has a private value for example this value name is a
, then I set it's value to 10.
How I can access to this variable with its value (10) in another class?
(I do not want to use friend function and friend class)
a.h
#include <iostream>
using namespace std;
static int s=0;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class a
{
private:
public:
void sets(int );
};
a.cpp
#include "a.h"
void a::sets(int y){
cin >> y;
s=y;
}
main.cpp
#include"a.h"
int main()
{
int i=0;
int q;
a a1;
a1.sets(q);
cout << s+1 << endl;
for (i=1; i<5; i++){
if (s == i) cout << "ok";
}
}