If I have 2 classes, person and hair for example, is it possible for person to access the protected pointer variable color_ ? and what would that code syntax look like?
class person
{
public:
constructor
etc...
}
class hair
{
public:
etc...
protected:
ptr * color_;
May I suggest using friend sparingly as it increases coupling b/w classes, at times unnecessarily, when alternatives like getters and setters exist. For instance, you can try something like this:
Yes I know I could rewrite the header file but in this particular situation I am not allowed to change the header file.
I am trying to implement a static member function that will be used in implementation of public methods, where the variable I am trying to access is inside another class's protected data (but is listed as a friend).
I have tried to use dot operator(.) to access it but it errors. something like
(maybe this is a bad example, supposing HairColor() is in class Person)
Why Hair should only be a different class and not also an attribute of Person (edit: i.e. Person contains an object type Hair), I'm not sure but I suppose you have your reasons
I am trying to access is inside another class's protected data (but is listed as a friend)