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

Friend Class of child try to access protected function of Parent

I've got a Parent Class and a Child Class. The Parent have a protected function called setId(int id). Now I want to make the setId function acessable by friend class of Child (lets call it Friend). Is this possible or do I have to reimplement the…
Marcus
  • 1,910
  • 2
  • 16
  • 27
-1
votes
2 answers

External lib friend function

I am using wgetch function from curses.h and want to call e.g wgetch(handle) where handle is private member of my class. Is there any way to do it without defining new friend function of my class (like below) or maybe making it method somehow? class…
Mat3o
  • 5
  • 1
  • 4
-1
votes
1 answer

friend template class in template class

I am learning data structure using C++. I copy the code into my computer just like the book tells me, but the compiler shows Chain is not a class template. template class ChainNode{ friend class Chain; private: T data; …
孙维松
  • 47
  • 4
-1
votes
1 answer

About Complex numbers using friend function

I am trying to add 2 complex numbers by using friend functions and constructors to initialize values but getting error 'Undefined reference to complex1::complex1()' can someone suggest where am I going wrong. #include using namespace…
-1
votes
2 answers

Not able to access private member through friend function

#include using namespace std; class S; class R { int width, height; public: int area () // Area of rectangle {return (width * height);} void convert (S a); }; class S { private: int side; …
-1
votes
1 answer

In C++, why do code examples often use memory locations when overloading operators?

I've written a little sample code below. #include #include using namespace std; class Box{ int l; //length int b; //breadth int h; //height public: Box(){ l =0; b = 0; h = 0;} Box(int d1, int d2, int d3){…
Gimingo
  • 1
  • 1
-1
votes
1 answer

Overloading Operators in Templates Classes with Friend Operators

Consider this following class Operand: It is a pretty straight forward class as it takes in a single Parameter and defines a bunch of overloaded operators and for simplicity of testing this class I chose to use a float type since there are division…
-1
votes
1 answer

Trying to understand the keyword friend correctly via OOP in c++, coding issues

OK so here's my question, I'm trying to understand the use of friend in C++ with a working example on my PC for reference. I have everything set up in different classes, which are connected to one another with the .h files etc. (I think anyways).…
Danny
  • 1
  • 1
-1
votes
1 answer

How to pass an object(type a) to a private object(type a) of another object(type b) through function of friend

#include #include using namespace std; class Flight; class Time { private : int hour; int minute; public : Time(int hour,int minute){ this->hour = hour; this->minute = minute; …
WJ LIM
  • 31
  • 9
-1
votes
1 answer

Inequality check within template class

I'm trying to make the iterator work properly, and for the inequality i != a.end(). I get the error no know conversion from argument 2 from 'const a3::vector::iterator' to 'const a3::vector& for the friend function. I need the…
student
  • 57
  • 1
  • 5
-1
votes
1 answer

Template class compilation error. Not recognising class created

I am having a 2 compilation time error. Here is my class definition and implemetation #ifndef QUEUE_H #define QUEUE_H #include #include "MyException.h" using namespace std; template class Queue; template ostream&…
Keaton Pennells
  • 189
  • 2
  • 4
  • 15
-1
votes
1 answer

Getting user's location in android app simultaneously

I'm planning to make an app which will find my friend's specific location and the coordinates will move as my friend moves. Is there any way other than using his phone number?
-1
votes
1 answer

encapsulation and friend classes in C++

I'm studying C++ container and iterators and I'm trying to implement a rudimental linked list, just to get the hang of thi inner workings of iterators and container related stuff. I defined a node class, along with a list class and the associated…
Luca
  • 1,658
  • 4
  • 20
  • 41
-1
votes
2 answers

What is the difference between ` inline friend ...... ` functions and `friend inline .....` functions?

When I am checking declarations from string.h file, I saw these things: friend inline void cat(const String&,const SubString&,const String&,String&); inline friend void cat(const String&,const SubString&,const String&,String&); What is the…
Madhu Kumar Dadi
  • 695
  • 8
  • 25
-1
votes
2 answers

kindly suggest the mistake in following code?

#include template class myclass; template void f(myclass &c); template class myclass { private: T value; public: friend void f(myclass &c); T getvalue() { return…
neha
  • 1
  • 1