Accessing Private Member Functions
Aug 21, 2013 at 8:41pm
Real quick question. Say I have the following code:
1 2 3 4 5 6 7
|
class Base
{
public:
// Some public shit
private:
int secret();
|
I then innitialise an object BaseObject:
Base BaseObject
Now I wish to call
secret as follows
BaseObject.secret();
Now I know this is incorrect cause its private and cannot be accessed outside the class, but then how should I call it?
Aug 21, 2013 at 8:43pm
You can call it inside other member functions of the class.
Aug 21, 2013 at 8:44pm
Thanks may I please get an example?
Aug 21, 2013 at 8:53pm
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
struct A
{
void f() const { g(); }
private:
void g() const { std::cout << "Hello World"; }
};
int main()
{
A().f();
}
|
Aug 21, 2013 at 9:01pm
Vlad to the rescue..again thanks man!
Topic archived. No new replies allowed.