Accessing Private Member Functions
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?
You can call it inside other member functions of the class.
Thanks may I please get an example?
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();
}
| |
Vlad to the rescue..again thanks man!
Topic archived. No new replies allowed.