How can I access the private data member without friend class?
Unsolved
General and Desktop
-
How can i access the Private data in another class?
class Instruments { public: void isConnected(); private: std::share<InstrumentsPrivate> m_data: // InstrumentsPrivate contain all private data. } class Channel { void start(std::share<Instruments> deviceHandler ){ // How can I access the deviceHandler->m_data->(member of InstrumentsPrivate). } }
I do have one solution i can make the friend class of instruments. But this public API Header file . I can't add the friend class in public header file. is there any alternative solution?
Thank you,
-
You cannot, without modifying the class where the private member is declared. That's why it was made private. Without a get/set method pair it is only visible internally to the class.