Questions tagged [friend]

In object-oriented programming, friend refers to a method or class that has access to some non-public aspects of a particular class.

In object-oriented programming, friend refers to a method or class that has access to some non-public aspects of a particular class.

Different programming languages use the friend keyword differently. Make sure it is clear which language you are asking about.

1518 questions
0
votes
0 answers

Social networking v2

I'm trying to make a network of friends like in this example previous to the final correction of JenB in here, since it is more comprehensible for me and Bryan Head said it would be the way he would do it with fewer agents. I'm planning to use…
0
votes
1 answer

friend class across namespaces & different .H files

I'm trying to make the following compile under VS 2008 SP1 C++ project, but the friend class statement doesn't seem to have any effect. (See error message in the last code snippet.) What am I doing wrong with the friend definition? //…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
0
votes
2 answers

Access private members of a class instantiated using interface

I have a class derived from an interface and a friend class of the derived class. I want to access the members of derived class which is instantiated as interface. It looks like this: Interface: class AInterface { public: virtual ~AInterface() =…
kwadhwa
  • 129
  • 1
  • 8
0
votes
1 answer

Give only some derived classes access to member functions from base class

Suppose I have four classes, A1, B1, B2, and C1. A1 is the base class, B1 and B2 inherit publicly from A1, and C1 inherits publicly from B1 and B2. B1 and B2 are virtual classes. Now, suppose I need a member function defined in A1. Is it…
JohnTravolski
  • 131
  • 1
  • 1
  • 6
0
votes
1 answer

Selectively hide member of member of class

// PhysicalTraits.h struct PhysicalTraits { unsigned int age; // years double height; // meters PhysicalTraits(const double H = 0.0, const unsigned int A = 0u) : age (A), height(H) {}; ~PhysicalTraits() {}; }; //…
Vladislav Martin
  • 1,504
  • 2
  • 15
  • 34
0
votes
0 answers

Friend declaration not working with typedef

When I write a friend declaration like this template struct Foo {}; struct Bar { friend class Foo; }; everything is fine. However, when I use a typedef template struct Foo {}; struct Bar { typedef Foo
463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
0
votes
1 answer

C++ friend class for linked list node

) Hi everyone! So I have two classes named DoubleNode (represents double linked list node) and DoublyLinkedList (it's implementation). Inside the DoubleNode class I specify that DoublyLinkedList would be it's friend class, but IDE and compiler sees…
0
votes
1 answer

Template overload of insertion operator >> causing cin issue

so I've got a project where I am inserting user entered data into classes. So I've overloaded the >> operator. Because I have classes with similar structures, I made the overload a template to try to save time. Making this template overload a friend…
0
votes
4 answers

Unable to declare 2 friend overloaded<< in a template .h

I'm trying to create two overloaded operators in a template BSTree.h and am encountering errors that really don't tell me what the problem is. Running a search on the error codes seperate or in conjunction hasn't yielded anything for me. The first…
Moniker
  • 5
  • 2
0
votes
1 answer

My friend functions are not getting access to private variables

So I am trying to build a class that can hold information about atomic elements and then do calculations with them. I am getting an error with my overloaded * friend function that says the variable atom_weight is private within the context of the…
jchud13
  • 55
  • 6
0
votes
1 answer

calling the destructor from a friend class

I am using friend classes and I want to use rec's destructor when I call DeleteItem from my list class. However, there is a pointer pointing to the record that I want to delete, so I do not know how to call the destructor so it will do what I want.…
0
votes
0 answers

Overloading << operator for a nested class in a template class

I want to overload the << operator to accept an object of the nested class and print the items of the nested class. This is very easy if I define the friend function inside the nested class like template class X{ public: class Y{ …
CodeMan
  • 45
  • 6
0
votes
2 answers

friend function not printing out what it should

whenever I run the program, there is no output, the program just ends. Am i doing something wrong? I'm sure there's something i missed but i can't seem to figure it out. #include #include using namespace std; class…
0
votes
1 answer

Scope of Variable in Friend Operator

For one of our class assignments we had to implement a polynomial class. It stores the coefficients of a polynomial and outputs the answer. In my class definition, I have a friend operator that outputs the function: friend std::ostream& operator <<…
Aryan
  • 608
  • 6
  • 15
0
votes
3 answers

Easier way to write encapsulated parent/child data structure?

From time to time I find myself often writing a data structure of "parents" and "children", where: A parent has references to 0 to N distinct children. A child has a reference to 0 parents or 1 parent. The reference must be mutual. For any given…
Hatchling
  • 191
  • 1
  • 7