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
1 answer

Overloading friend iostream operators in a varadic template

I'm trying to implement the iostream operators as a friend function to a variadic class template. #include #include template class StudentInformation { public: //friend class Student; using Members =…
0
votes
0 answers

Private Data member is inaccessible in Friend Function

The private data member is inaccessible. Although i have declared function as friend of class. Can anyone help me. class ONE; class TWO { public: void print(ONE& x); }; class ONE { private: int a, b;…
Shoaib Khan
  • 51
  • 1
  • 10
0
votes
1 answer

Declaring one derived class a friend to access private member of base class

I have the following inheritance structure: template class Base { protected: int a; }; template class Derived1 : public Base { }; template class Derived2 : public Base { }; What I'd like is to…
tree
  • 229
  • 3
  • 12
0
votes
1 answer

Friend stream operator in c++17 of a simple class template

My question is different because it is pertaining to a newer version of C++. This question was asked already here and I'm referring to this answer. However this was asked and answered back in 2009 and it is quite dated to the current compilers and…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
0 answers

Forward declaration friend

I have two classes A and B, where I would like to access the private members of B from A. class A; // Forward declaration class B { friend class A; // A is a friend of B A a; // error: 'B::a' uses undefined class 'A' private: int…
evolved
  • 1,850
  • 19
  • 40
0
votes
0 answers

Intentional friend class redifinition and -fstack-protector

I have been trying testing if multiple definition of a friend class in different .cpp files would work. To do that I defined a main class inside main_class.hpp file: class main_class { private: int a; int b; int gimme_a() { …
K. Koovalsky
  • 596
  • 4
  • 17
0
votes
1 answer

C++: Friend Functions

class A { friend void display(); }; friend void display() { cout<<"friend"; } int main() { display(); } Works fine... class A { friend void display() { cout<<"friend"; } }; int main() { display(); } It shows : display is not…
0
votes
1 answer

Return type deduction for template in-class friend functions in clang

So up front, what I'm trying to do is not an really intended use case for in-class friend definitions. But it does work under g++ and, best I can tell, is supposed to work according to C++14 specs. For the purposes of discussion, clang is 5.0.0 and…
KSquared
  • 58
  • 7
0
votes
1 answer

FBML: select one of the user's friends

I'm designing an app based on FBML. I want to fetch a user's friends list and pick any one of them. Can you please help me with this?
Shrey
  • 21
  • 4
0
votes
1 answer

Is there a way to make [incr Tcl] classes friends?

Is there a way to obtain a friendship between classes in incr Tcl? Consider the code below. package require Itcl ::itcl::class A { private { proc f { } { puts "==== A::f" } } } ::itcl::class B { public { …
Vahagn
  • 4,670
  • 9
  • 43
  • 72
0
votes
2 answers

C++ find_if member variable of another class

So I have a class called Song, and another class Called SongLibrary. The Songlibrary just contains a set of all songs and appropriate methods. I am currently trying to make a function to search the song library and check if a song has a particular…
Michael Grinnell
  • 922
  • 1
  • 12
  • 32
0
votes
1 answer

Facebook iframe canvas friend selector

I am in the process of converting my FBML application to iframe as per Facebook's new requirements: No new FBML applications We will stop allowing new FBML applications, but will continue to support existing FBML tabs and applications. Instead, we…
Andy
  • 443
  • 1
  • 6
  • 21
0
votes
0 answers

Friending a variadic template function from a template class

How can one friend a variadic template function from a template class? Nothing I do does seems to work as the friend function declaration within the class seems to introduce an ambiguous overload for the variadic function For example this does not…
Curious
  • 20,870
  • 8
  • 61
  • 146
0
votes
0 answers

C++ Munmap Error and Allocating memory in a friend function

this is my first time posting here, so apologies if this is improperly formatted. Anyway, this block of code has been causing me nothing but problems for the last few hours. From what I can tell it ends up with unspecified behavior, because when run…
0
votes
2 answers

Friend status for derived classes of purely virtual class

I ran into the following problem and I don't really know what the best way is to approach this. I want to evaluate expression objects that are constructed with a foo object. The expression class and its derived classes should be allowed to access…
Ganymed_
  • 13
  • 4