问题
Hello I am trying to access a private member function is Gtest
.
The code looks somewhat similar to this. So, how can I access static void Pri_fun
?
using namespace std;
class test{
};
class abc{
public:
friend class test;
private:
static void Pri_fun()
{
cout << "private fun called \n";
}
};
int main()
{
abc ab;
test *abd;
abd->Pri_fun();
}
回答1:
Since it's a static function, you should access it via the class name:
abc::Pri_fun();
You should make a caller function though, or call it from the friend class' constructor:
class test{
public:
void foo()
{
abc::Pri_fun();
}
};
or
class test{
public:
test()
{
abc::Pri_fun();
}
};
来源:https://stackoverflow.com/questions/12953107/how-to-call-a-private-function-via-friend-function