Hello people,
I have two classes everyone with private data.
I want only one function from each class to access private data from another class. I have checked "friend" function but It needs the class object as an argument. That is making things complicated on my side and I have no idea on how to do this.
Is this possible? If yes, how can I archieve that?
Thanks alot
Stefano Mtangoo
455
Senior Poster
Recommended Answers
Jump to PostIf the private data is static, i.e. all instances of the class share the static private data, then there is no need for the class object as an argument.
If the private data is non-static, then you must have the class object as an argument because the object instance …
Jump to PostSo can you explain a little bit on Static thing?
Essentially a static member variable (be it of any type) is a variable that is common to all non-static instances of the class.
Maybe the following explains it a bit ..#include<iostream> using namespace std; // forward …
Jump to Postcan I use combination of static variable and friend function to expose that variable to only one method of another class?
Yes you can, like so ..
#include<iostream> using namespace std; // forward declaration class A; class B { public: B(){} void set(int ii); }; class A …
Jump to PostCan this Static variable be a pointer?
Yes it can. About small tutorials, I'd bet that you'll find reasonable ones by searching the web for example "static member variable in c++".
All 13 Replies
mitrmkar
1,056
Posting Virtuoso
Stefano Mtangoo
455
Senior Poster
mitrmkar
1,056
Posting Virtuoso
Stefano Mtangoo
455
Senior Poster
mitrmkar
1,056
Posting Virtuoso
Stefano Mtangoo
455
Senior Poster
mitrmkar
1,056
Posting Virtuoso
Stefano Mtangoo
455
Senior Poster
sheff_cc
0
Newbie Poster
mitrmkar
1,056
Posting Virtuoso
sheff_cc
0
Newbie Poster
mitrmkar
1,056
Posting Virtuoso
sheff_cc
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.