"Break" into secret data...

Hello!
Please, I try to "invent" a function mmm, which would try to take private data, and, as it would not be allowed, I woudl "have" to make these data public to make mmm success it. Where did I do the mistake? Many thanks!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  class First{

int a;
int b;

public:
 First(int c,int d):a(c), b(d){};
 int sss(){ return (a+b); }

};

int mmm(int x, int y) {
int z=x+y;
return z;
}


int main(){
First sum1(2,3);
First sum2(4,5);

cout<<sum1.sss()<<endl;
cout<<sum2.sss()<<endl;


int r;
r=mmm(First.a + First.b);
cout<<mmm()<<endl;


return 0;
}
Last edited on
r=mmm(First.a, First.b);

What are you trying to do here? Becuase it doesnt do what you think it does.
Hello, I try to write szch a code, that data int a and int b would HAVE to be changed from default to public, meaning, such a code that would not work if a and b were default (private) and WOULD work if both were public.
I corrected "," to "*" in line 27.

I try to "use" a and b which a re "secret" so that I would habe to change their status from private to public.

So, I first need code which would not wrok with a and b being private

THEN I woudl correct the mistake just by changing a and b to public.
Here:

r=mmm(First.a, First.b);


..I want to sum a and b (a+b) , //I wonder how to do it from mmm() anyhow!
Last edited on
You're correct, if you want to use mmm as a regular function those members will have to be public, however you can also implement mmm as a class method which would allow you to access those private members. Your other option is to make "getters" and "setters" for those variables, which would be public functions like:

1
2
3
int geta(){
    return a;
}
Last edited on
Many many thanks!!!
Topic archived. No new replies allowed.