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
2 answers

Code Pattern for accessing owning class from within a sub-component class (Friend Interfaces?)

If I have a class (class P) which makes use of some other re-usable component (class C) (eg a state manager), then if that component needs to access some data within my top level class (P), then what choices do I have? The key thing is that I dont…
fpdave100
  • 11
  • 5
0
votes
2 answers

C++: friend template class / template non-type parameter

I want to implement generic graph classes and I am still having problems which narrowed down to the following code: template class B { template friend class A; }; template class A { private: std::vector *>…
Sir Tobi
  • 142
  • 1
  • 8
0
votes
1 answer

How to access private member function using friend class object?

In main, I want to access the display function. Here, in class B I declared class A as friend. So i thought that it is possible to access the private member functions. But i dont know how to do that. #include class A { public: class…
senthil
  • 21
  • 1
  • 3
0
votes
0 answers

gcc:g++ being bureaucratic with template template friends

In header view.h: template class V> void Operate(S c, const V& vx); template class U> class ViewBase { template class V> friend void Operate(S c, const…
skm
  • 329
  • 2
  • 9
0
votes
1 answer

Class using each other's member and error

I have two classes using each other. Basically, I have an helper class and an head class (I'll call it like that, head uses helper, but helper access members from head). So it looks like that : class CHead; class CHelper { public: …
Yannick
  • 830
  • 7
  • 27
0
votes
2 answers

How to invite facebook friends for app request notification?

I have a non game app and I want to invite my facebook friends by send notification. Facebook Platform Upgrade from last few months, check this link. Now How can I send invitation to friends? should I use sharing wall post instead of…
Jagdev Sendhav
  • 2,875
  • 4
  • 15
  • 24
0
votes
0 answers

Restrict visibility of friend classes in C++

I want to allow a private method defined in class A to call a private method defined in class B. I cannot declare a single friend method because class B's definition is already known by A (A already uses B), and including A's header in B would go…
greenback
  • 1,506
  • 2
  • 17
  • 29
0
votes
2 answers

Friend parent class cannot access private constructor in child

I want to create a parent class Base which has factories for its subclasses Derived1, Derived2 etc. The constructor of Base and all its derived classes should be private. I try to do it this way: base.h: class Derived1; class Base { …
Anton Poznyakovskiy
  • 2,109
  • 1
  • 20
  • 38
0
votes
3 answers

How to access friend functions correctly?

I'm trying access a friend's method as defined the following. I have 4 files. Two header: Header a.h: #include "b.h" class A { public: A(); ~A(); void testStuff(int i); }; Header b.h: #include "a.h" class A; class B { friend…
q9f
  • 11,293
  • 8
  • 57
  • 96
0
votes
1 answer

Use the private variable of the superclass with friend

I have a class A with a private variable a. Class B is a subclass of A. In class B_Test, I would like to wrtite something like "B b; b.a;", I put friend class C in both Class A and Class B but it still no works. Any idea? Thank you. (Sorry I make a…
xieziban
  • 77
  • 1
  • 5
0
votes
1 answer

Class inheritance and friendship project

I stumbled across what seems to me a very interesting problem. I am not asking for a solution to this problem, only advices on how to continue with my code and I'd like to know if derived classes inherit the friends of the base class. This is the…
0
votes
4 answers

What are security risks with friend functions?

What are security risks with friend functions? Will it compromise encapsulation and data-hiding in C++? I am not able to get the proper answer in-spite a lots of research. Can someone give a concrete answer with example?
Amit Shakya
  • 1,396
  • 12
  • 27
0
votes
1 answer

Friend has access to friend's member, but can't seem to update friend's member

Within the Dealer class, I declare Player as a friend class. Note that deck is a Dealer member, and I have the following Dealer function: deque> Dealer::deal(int numOfCards){ deque> dealtCards; for (int i…
ch-pub
  • 1,664
  • 6
  • 29
  • 52
0
votes
1 answer

Strange behavior of templated operator<<

I cant understand a behavior of operator<< in my class: header: #ifndef VECTOR_H_ #define VECTOR_H_ #include #include template class Vector { static const int EXPANDER = 10; T* array; int next; …
ovnia
  • 2,412
  • 4
  • 33
  • 54
0
votes
1 answer

How to writer query in Neo4j by java

My data structure is: Node node1 = graphDb.createNode(); node1.setProperty("id", "123"); Node node2 = graphDb.createNode(); node1.setProperty("id", "456"); Node node3 = graphDb.createNode(); node1.setProperty("id",…
cow12331
  • 245
  • 2
  • 3
  • 9