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

Template class specialization and friend classes

I am in the following situation: template class Foo { }; // specialization for 0 template class Foo<0> { friend class Foo; }; That is, I need that Foo is friend of Foo, but I have a compiler…
Nick
  • 10,309
  • 21
  • 97
  • 201
0
votes
1 answer

unable to match function definition to an existing declaration in cpp

I'm doing a course project and I created a matrix class with 2d vector in cpp. I'm trying to override * operator to an global operator with the matrix obj. this is my declaration: friend Matrix operator * (T t, const Matrix &m); and this is…
Gabriel
  • 121
  • 1
  • 1
  • 8
0
votes
2 answers

Accessing private data members using friend class

I learnt that declaring a class as a friend class enables it to use the contents or members of the class in which it is declared. I used the following code: #include using namespace std; class two; // forward class declaration class one…
user3124361
  • 471
  • 5
  • 21
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

cannot access protected member declared in class from a friend function in derived class

i've a base class as follows: //base class- arrayListType.h class arrayListType { public: //some function members; protected: elemType *list; int length; int maxSize; }; and then a derived class: //derived class- polynomialType.h #include…
bikrathor
  • 96
  • 1
  • 1
  • 7
0
votes
1 answer

A friend function deceleration cannot get accesses to the function declaration

I'm working on a homework assignment for school. For the main loop I circle trough the Objects and call their Update function, each Object has two Object pointers witch are used to make a linked-list. I made these pointers private, and made two…
0
votes
1 answer

Friend statement of singleton causing linker errors

I get linker errors when building my program. The problem seems to be my NetworkManager singleton gets pulled into Networkable with the friend statement. I read that this can happen when having the instance declaration in the .hpp file, but if the…
Z317
  • 1
0
votes
1 answer

ostream << operator with template class, cannot access private members

I followed instructions I found on stackoverflow to implement linked list template class, I did it as follows: template class List; template std::ostream& operator<<(std::ostream&, const List&); template class…
0
votes
1 answer

What are the scope limits of friend specifier

Suppose I have an object X and a proxy. I want to control lifetime of the proxy so that it cannot be extended beyond temporary object, returned by a method of the X. I can't understand if the way I did it is due to what standard allows. class…
GreenScape
  • 7,191
  • 2
  • 34
  • 64
0
votes
1 answer

Constructor(method) not being accepted as a friend

I currently have something like this. I would like to only allow the bar class to create an instance of the foo class so I have made it a friend of foo and made the constructor of fooprivate. foo.h class foo { friend class bar; …
MistyD
  • 16,373
  • 40
  • 138
  • 240
0
votes
1 answer

class not being recognized as friend

I have two classes say foo and bar. The constructor of foo is private so as to only allow the bar class to instantiate it. // foo.h class foo { friend class bar; private: foo() {} }; // bar.h class bar { public: bar() { foo* f =…
MistyD
  • 16,373
  • 40
  • 138
  • 240
0
votes
1 answer

Compilation error Friend class unable to access field

I am trying to compile QT5.3 The files in question are qv4executableallocator_p.h and qv4executableallocator.cpp. Relevant code snippet from the header is below struct Allocation{ Allocation() : addr(0) , size(0) , free(true) ,…
bobby
  • 2,629
  • 5
  • 30
  • 56
0
votes
1 answer

Accessing static member function from friend function

I am using a linked list to implement a set class. In order to hide my struct Node from the users, I put the struct Node declaration into private. Furthermore, I overloaded the operator +, which denotes union operation between two sets. Because I…
Fan
  • 217
  • 3
  • 14
0
votes
1 answer

How to make parameterized Base a friend of Derived in CRTP?

I would like to implement the CRTP on a parameterized Base, and make Base a friend of Derived: template