In object-oriented programming to allow access to "private" or "protected" data of a class in another class, the latter class is declared as a friend class.
Questions tagged [friend-class]
83 questions
0
votes
1 answer
Friend of the class is inaccesible
i am trying to write a very simple code as a practice. The problem is when i make friend a member function of one class to another, it says inaccesible but when i declare the whole class as friend of another class it works fine.
#include…

Aqib Naeem
- 431
- 3
- 11
0
votes
0 answers
Can you create class methods in Objective-C only visible within your library?
I found this StackOverflow question on friend classes in Objective-C which was similar to the issue I'm trying to solve, but not quite the same. So I'd like to extend their example.
Suppose I want the ability to hand a Monkey multiple Bananas and…

stevendesu
- 15,753
- 22
- 105
- 182
0
votes
2 answers
C++ access member-function from friend class
Is there a way to access member-function from the friend class?
// foo.h
template
class A
{
bool operator()(Item* item)
{
ObjectClass c = get_class_from_item(item); // compiler error
...
}
};
class B
{
…

maverik
- 5,508
- 3
- 35
- 55
0
votes
2 answers
Where in derived class or base class should I declare friend class?
I have a derived class that implements an interface(abstract class) in C++. This interface has a couple of protected functions whose implementation are defined in derived class.
Now I'm trying to access these protected functions in derived class…

Vince
- 81
- 4
0
votes
2 answers
Make all derived template classes friend of other class in C++
Let's say I have to following hierarchy:
template class Base {
protected:
T container;
};
template class Derived1 : public Base {
public:
void f1() {
/* Does stuff with Base::container */
…

TKr
- 13
- 3
0
votes
2 answers
Access a function in derived class through virtual call to it in base class
The question comes up with me when reading chapter 13 of accelerated c++.
There are three classes involved in this question, e.g. class Core, class Grade and class Student_Info. Core is the base class. Grade is the derived class inherited from Core.…

Chris Jing
- 39
- 5
0
votes
1 answer
Friend classes and overloaded operators
First off, this is for academic purposes. I'm extremely frustrated, and I have even been working this out with a friend for half the day.
We're working with both overloaded operators and friend classes and this lab has made me feel like a complete…

Trace Langfels
- 13
- 4
0
votes
1 answer
Using or not using new for creation of a class in another
I have been solving a question, Dijkstra's Algorithm, in C++. I've implemented it using adjacency list.
So I have a class for a node, a class for a minHeap, and a class for the Graph.
class node
{
int vertex,weight;
node *next;
friend…

revanthc97
- 1
- 1
0
votes
0 answers
Friend Class to access the protected virtual function in C++
I have three classes: Class A, Class B and Class C. Class B is derived from Class A. A protected pure virtual function declared in class A is defined in Class B. Class C is a friend function of Class A. Now I need to call that virtual function from…

Jackzz
- 1,417
- 4
- 24
- 53
0
votes
1 answer
C++ friend class invalid use of incomplete type OOP
I have decided learn some OOP and I started get rid of conditionals (I know in this program this in unnecessary but I have to start with simply example).
In class DirectConditions, I have my conditions and I would pass object of SnakeGame by…

Klemens
- 53
- 6
0
votes
3 answers
C++ friend class map
So i have problem trying to access a friend class properties, i need a pointer to the first item in the map.
class.h
class A{
private:
map database;
public:
......
class B{
private:
…
0
votes
1 answer
Creating Friend Class instance in Function parameters
I am new to working with C++. I need to declare an instance of a class as the parameter of a function in another class, with the parameter instance declared as a friend. I illustrate with an example.
class foo(){
private:
void a(){
…

agm
- 1
0
votes
1 answer
c++ Can a class contain a class member that is friends with it?
I have a class called Restaurant that contains an Employee member. Now Employee is a friend class of Restaurant. When I try to compile this I get errors on the Employee mCurrentEmployee saying that its missing type specifier - int assumed. Why does…

Evan Nudd
- 216
- 2
- 10
0
votes
1 answer
How a friend class can access a private member of a nested class?
Consider the following example:
class SIP{
public:
friend std::ostream& operator<<(std::ostream& os, const SIP& c);
private:
class BusStop;
std::vector mbusStops;
};
class SIP::BusStop{
private:
…

Tomasz Kasperczyk
- 1,991
- 3
- 22
- 43
0
votes
1 answer
Accessing member functions of other classes into member function of `this` class using composition or friend classes
I am writing a class using 'composition' as follows -
class fibonacci
{
private:
FibonacciDynamic dy();
FibonacciRecursive re();
FibonacciSequential se();
int count;
public:
fibonacci(int a):count(a){};
void disp();
};
void…

yuvi
- 1,032
- 1
- 12
- 22