Friend class not working

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

I am getting the typical '... is private within this context' error. Can you tell me what I am doing wrong? Code is shortened for readability.

in class SceneEditorWidgetController: (settingsdialog and the variable used here is defined in the header)

SceneEditorPluginWidgetController::SceneEditorPluginWidgetController() { } void SceneEditorPluginWidgetController::configured() {     priorKnowledge_setting = settingsDialog->priorKnowledgeProxyFinder->getSelectedProxyName().toStdString(); //This is the context } 

My class SettingsController.h

namespace Ui {     class SettingsController; } namespace GuiController {     class SettingsController : public QDialog     {         Q_OBJECT         friend class SceneEditorPluginWidgetController;     public:         explicit SettingsController(QWidget *parent = 0);         ~SettingsController();      private: //it is private here         Ui::SettingsController* ui;         IceProxyFinderBase* priorKnowledgeProxyFinder;     }; } 

I cannot modify the IceProxyFinderBase class, but it was used exactly (I'm probably blind?) like this before.

Could somebody please explain what I am doing wrong?

回答1:

With an unqualified class name, the friend declaration declares that a class of that name, in the surrounding namespace, is a friend, if such a class exists. So this is equivalent to

friend class GuiController::SceneEditorPluginWidgetController; 

However, your comments say that the class is actually in the global namespace, not GuiController, so this doesn't make it a friend. You'll need to qualify it correctly:

friend class ::SceneEditorPluginWidgetController; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!