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

Friend methods in C++ is not working

I wrote the following code: class Osoba{ private: string imie, nazwisko, kolorOczu; friend void Dziecko::coutall(); public: Osoba(string imie, string nazwisko, string kolorOczu):imie(imie), nazwisko(nazwisko), kolorOczu(kolorOczu){}; …
tomdavies
  • 1,896
  • 5
  • 22
  • 32
0
votes
1 answer

Redefining Friend Function of Base Class in Derived Class

I want to redefine the operator* function that is originally defined as a friend in the Vector class, in a derived class, BigNum. Specifically I want to call the Vector version of operator* and then do some other things to the result of that…
bcf
  • 2,104
  • 1
  • 24
  • 43
0
votes
2 answers

C++ Friendship / Polymorphic Classes Error

In C++, I am using polymorphic classes and friendship to make a basic 'friends group'. However, when I am trying to access the private age function of the class person, which is a friend of the class Boy, I cannot access it. What is the problem? /*…
user2976089
  • 347
  • 1
  • 5
  • 14
0
votes
1 answer

Inaccessibility when friend struct inherits class

I have a situation where I want to hide a base class and limit the classes that can inherit from it: namespace _detail { class Private abstract final { struct Base abstract { protected: Base() {} }; …
NmdMystery
  • 2,778
  • 3
  • 32
  • 60
0
votes
2 answers

How can I use friend classes with inheritance and templates

I've got a special configuration to build and I don't know how to write this : template class A { protected: VarType m_myVar; } template class B : public A { } class C : public B { …
fcaillaud
  • 31
  • 7
0
votes
1 answer

c++ --direct-- access of class members in non-member function bodies

The following example is obviously wrong, but I would like to know if it possible to achieve something like the following extern int return_value(); class A { private: int k = 1; public: friend int return_value(); }; int return_value() { …
woosah
  • 843
  • 11
  • 22
0
votes
2 answers

construct foreign classes from database in PHP

Firstly, it's not a problem to construct classes from a database, i.e. mysql, it's more a question about performance. If I have a Class A which depends on class B. class A { protected $depend; public function __construct($id == null) …
Felix
  • 2,531
  • 14
  • 25
0
votes
2 answers

C++: Two classes referencing each other

So to toy with friend functions, I decided to make a Child class and a Mother class. The Mother class has a data member that is a Child. The Child class makes two methods of the Mother class friend functions. When I compile though, it seems that no…
Rstevoa
  • 271
  • 4
  • 17
0
votes
1 answer

iOS sort facebook friends who are using one particular application from my friend list

I have one query in fetching out some particular friends from my friend list. I had created one iOS application in which user can login via facebook. Now I want to get the list of from "my friend" list, who are using that application. Does any…
Dishant
  • 917
  • 2
  • 8
  • 25
0
votes
2 answers

Implementation of friend overload << operator with templates

I can't figure out the correct syntax for templated friend overloaded operators. Using the code (I'm only showing the relevant stuff) from the class header (please don't tell me to change anything from this section): #include using…
Bobazonski
  • 1,515
  • 5
  • 26
  • 43
0
votes
2 answers

C++ : Restricting object instantiation with friend classes

I have a class, House, which contains a selection of classes, Rooms, as member variables. It doesn't in itself have any children. Room is a base class and it has several child classes - Bedroom, Bathroom, etc. I want to be able to limit creation of…
0
votes
1 answer

Template operator of a template class requires access to other specialisations

I have implemented a matrix class using CRTP. For the matrix multiplication, I would like to use a friend operator*. The problem is that, according to this question and my own experience, I need to define the operator* inside the class to make it…
lytenyn
  • 819
  • 5
  • 21
0
votes
1 answer

Friend template function

If I have namespace A { template inline void SomeFunc(T& archive, Object* object) { // ... } } and a non-template class namespace B { class Manager { // ... template…
Kristian D'Amato
  • 3,996
  • 9
  • 45
  • 69
0
votes
4 answers

Using constructor of Friend Class

I have two classes A and B. A has declared B as a friend. In B I would like to instantiate A in method func() (i.e I am trying to instantiate A outside of the constructor of B). To my suprise this seems to be not allowed in C++. This is the…
Mustafa
  • 253
  • 5
  • 22
0
votes
1 answer

Nested class does not name a type

Getting an error in g++ List.cc:19:1: error: âIteratorâ does not name a type when . Header is the following class List { private: class Element { public: char data; Element *next; Element *prev; Element(Element *n,Element *p, char…
CChiste
  • 131
  • 1
  • 2
  • 13