Friend函数访问静态库中定义的类的私有成员 [英] Friend function access the private members of class defined in static library

查看:257
本文介绍了Friend函数访问静态库中定义的类的私有成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C ++编写的静态库。我还可以获得静态库中定义的类的头文件。



我可以访问静态库中定义的类的私有成员,类声明?

解决方案

你的意思是你想改变库附带的头文件?无法保证在这里添加 friend 声明是可行的。即使你的编译器说它没问题,你可能会把链接部分搞乱。

另外,如果那些成员是私人,你只是不访问它们。


I have a static library written in C++. I have also got the header files for the classes defined in the static library.

Can I access the private members of the classes defined in the static library introducing a friend function in class declaration ?

解决方案

You mean you want to change the headers that are shipped with the library? It's in no way guaranteed that adding friend declarations there will work. You might mess up the linking part, even if your compiler says it's ok.

Also, if those members are private, you just don't access them.

这篇关于Friend函数访问静态库中定义的类的私有成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆