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

C++ Derived classes cannot modify a base class' attributes but an external class can

I am doing a Poker Engine so that different PokerPlayer agents can play against each other in tournament simulations. Once my project is done, I would like people to submit their own agents in a PR. In order to do so, they would only have to derive…
samdouble
  • 452
  • 4
  • 12
-1
votes
1 answer

how to use a friend cin/cout function from base templated interface in derived class

i've defined the next templated interface which has a cin and cout friend functions: #ifndef IPRINTABLE_H #define IPRINTABLE_H #include using namespace std; template class IPrintable { public: virtual friend istream…
mega5800
  • 87
  • 7
-1
votes
1 answer

Why is the global function void showA(A& x) able to access private members of A class?

Why is the global function void showA(A& x) able to access private members of class A? I know that the function with similar method signature is declared as a friend of class A but the global showA() isn't the same as the function showA(A&) declared…
-1
votes
1 answer

How to execute friend class?

I tried to realize the friend class to provide the members's value for the member of another class. I' ve tried to make the object of class Friend and defined it as Attempt's argument and after replace &Friend::fri to object.fri() but it was not…
Konstantin
  • 111
  • 1
  • 8
-1
votes
1 answer

Friend Package Pattern problems

I came accross the friend package pattern described here: http://wiki.apidesign.org/wiki/APIDesignPatterns:FriendPackages I simply implemented the example but it does not work for me. I always get the error IllegalStateException: Something is wrong:…
Emanuel
  • 863
  • 9
  • 29
-1
votes
2 answers

Use friend class in gcc

I have this class that compiles in VC14, but when I try to compile in gcc 4.8.5, it doesn't work, I get "error: C was not declared in this scope". class A { }; class B : public A { friend class C; friend class D; private: class BB { …
danny
  • 7
  • 1
-1
votes
1 answer

How to write a friend (operator) method in a template?

So I'm trying to overload the operator + in a template class. the code compiles and runs but crashes at the use of the operator +. tried so many things, I think it's a syntax problem? any advice would be appreciated! The operator = is overloaded…
-1
votes
2 answers

C++ template class friend with all type

I have a Vector class and I overload the operator* I would like to be able to multiply a Vector of float with a Vector of int. I have the following code but when I compile him, I have an error because I don't have access to private fields. template…
-1
votes
3 answers

unable to access friend function in template class

The Pairwise class represents a pair with a key:value. I've made a template pair and was having errors trying to run with a key and value input to the class and printing it out. Given my main: #include "file_name.h" int main (){ …
Dracep
  • 388
  • 2
  • 13
-1
votes
1 answer

C++ Nested class (Make friend outer member function)?

My code: class Controller { private: class ControllerMetals { private: int m_size; Metals * m_metals; public: ControllerMetals(); Metals & getMetals() const; int…
loczek
  • 123
  • 1
  • 6
-1
votes
1 answer

How to implement a hierarchy class system

I'm a bit new to C++ way of handling this situation, so instead of using singleton pattern right away, I decided to ask this question instead to see if there's a better alternative. Is there any other way to implement a system, where we got a main…
buttons.png
  • 77
  • 1
  • 9
-1
votes
1 answer

Perform Matrix Operations using templates and operator overloading in C++

Here is my full code where I have performed addition,subtraction and transpose operations on matrices using templates and operator overloading. WHEN I DO IT WITH MEMBER FUNCTIONS , EVERYTHING IS FINE. BUT WHEN I TRY TO DO IT WITH FRIEND FUNCTION AS…
TheCoder
  • 51
  • 4
-1
votes
2 answers

Virtual-like friend functions?

I want to create interface like class Scalar { public: Scalar() {} virtual ~Scalar() {} //virtual members operators virtual Scalar& operator+() const = 0; virtual const Scalar operator-() const; virtual Scalar& operator=() = 0; virtual…
-1
votes
2 answers

Issue with a friend function in a class in C++?

I have a class with 3 fields a,b and c. I want to calculate the volume of a box with sides a,b or c. I want to do this with a friend function. However, when I compile the program the Compiler gives an error No global operator found which takes type…
A.Dimitrov
  • 109
  • 2
  • 2
  • 9
-1
votes
1 answer

Iterating through vector of unique_ptr of a struct with private destructor, by a friend, fails in VS 2017

This might be a question with simple answer, but I tried every solution offered by google results, yet unable to fix this in VS 2017.I have a struct B with private destructor. I have another struct A that is friend of struct B, and trying to iterate…
Swtsvn
  • 307
  • 1
  • 3
  • 12