Hi, I'm new to C++ and OOP. I've been having a problem with a concept.
class samp
{
int i;
public:
samp(int n)
{
i = n;
}
int func(samp ob)
{
return ob.i;
}
};
Now, i is a private member of the class samp. So, how can the parameter ob access i directly? I know func(ob) is a member function of the class. But I thought private members can only be accessed with a this pointer.
Silly, illinformed comment but thanks for playing anyway.
I mean, are you actually comparing a default browser on well over a billion devices with Firefox?
The way time and things are going, Mozilla might oneday surprise everybody by giving up Firefox estimating "no future growth potential" and moving it to the security and maintenance updates only mode. We've seen something like that before ... and Mozilla still doing it.
Question
Gigi Buffon
Hi, I'm new to C++ and OOP. I've been having a problem with a concept.
Now, i is a private member of the class samp. So, how can the parameter ob access i directly? I know func(ob) is a member function of the class. But I thought private members can only be accessed with a this pointer.
Can anyone explain why the above code works?
Link to comment
https://www.neowin.net/forum/topic/1025404-c-accessing-private-member-variables/Share on other sites
10 answers to this question
Recommended Posts