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

friend operator << and private access of template class member

After reading this answer, I made some tests and I came up with the following code: #include template class Test { int val{42}; friend std::ostream & operator << (std::ostream & flux, Test const & instance) { …
O'Neil
  • 3,790
  • 4
  • 16
  • 30
0
votes
1 answer

Friend functions with templates

I have a generic class , Array1d, with a friend function declared as, friend std::ostream& operator<< <>(std ::ostream& out, Array1D& a); and defined as template std::ostream& operator<< (std ::ostream& out, Array1D a){ …
Metafity
  • 35
  • 1
  • 6
0
votes
1 answer

.NET class access modifiers (friend and public)

I am developing a class library that will be used in several projects. In my class library, I have a "Shape" Class which has a number of properties. One of these properties is "Dimensions" returns a class with "Height" "Width" and "Depth"…
0
votes
0 answers

Android facebook friend list with pictures

I'm new in android studio and I'm trying to get my facebook friends list with their profile pictures and all of my result is just their names, could anyone of You help me to get it? Thanks for the reply :) My code to get the list: void…
0
votes
1 answer

C++ template specialisation friend iterator error: invalid use of incomplete type

For a project I'm working at, I've created a C++ library that encapsulates data structures. For each data structure, I've created custom iterators to navigate through data elegantly. Everything went fine until I've tried template specialization on…
0
votes
7 answers

Class hierarchy in C#: how to do it correctly? ('friend' keyword wanted)

I have a class: public class MyClass { private List folderList; // .... a lot of useful public methods here..... } Everything is fine. The list of folders is encapsulated, the class is accessible through public methods. OK. Now I…
Vitas
  • 243
  • 4
  • 10
0
votes
2 answers

Class friendship for subclasses

I have a class Controller which has the class Parent as friend: class Controller { // I can use x; }; class Parent { friend class Controller; int x; }; Is there a way to specify that the whole subclass hierarchy of Parent will have…
NoImaginationGuy
  • 1,795
  • 14
  • 24
0
votes
4 answers

operator overloading c++

I am trying to preform operator overloading in C++; for some reason the compiles keeps on giving me the error error: ‘bool Matrix::operator==(const Matrix&, const Matrix&)’ must take exactly one argument Now, I know that there is some way to to…
bass
  • 49
  • 1
  • 2
  • 4
0
votes
2 answers

Friend function and protected data

I have class class ScoreBoard: public die { //..// protected: bool mSetValue[6]; public: //...// friend void ValueSet(); }; and I would like to use that friendship to get access to mSetValue. So what I do in ScoreBoard.cpp…
user6247452
0
votes
1 answer

c++. compile error. am trying to add friend template function with enum template parameter

Please help with the next code: typedef enum {a1, a2, a3} E; template int foo() { return static_cast(e); } class A { A() {}; friend int foo(); }; The compiler says: error C2146: syntax erorr: missing "," before…
artyom.stv
  • 2,097
  • 1
  • 24
  • 42
0
votes
1 answer

undefined reference to all friend functions

I have two templated overloaded friend functions in my Set class that keep sending back the error Templatedriver.cpp:(.text+0x2a0): undefined reference to `std::ostream& operator<< (std::ostream&, Set
0
votes
1 answer

Trying to call a friend function of template class

I have a template, in which I have a declaration of a friend function, And lower, outside the class i have it's realization: template class AVLTree { public: template
KittyT2016
  • 195
  • 9
0
votes
1 answer

C++ creating a header that has template for overloading ostream

I am trying to get this to work but it comes up with an error message C2473 " operator << looks like a function definition but there is no parameter list." Basically, this is a header file and I want to declare a namespace and a template for a…
AliS
  • 3
  • 3
0
votes
1 answer

Template operator friend of template class with enable_if

How would I go about making a templated operator with enable_if a friend of a templated class? Here is an example of my problem: #include template class BasicString; template
lufinkey
  • 342
  • 4
  • 15
0
votes
3 answers

What happens when Classes that are friends have same name member variables

In C++, what happens when I have the following class House { public: House(); ~House(); private: int* m_peopleInside; friend class Room; }; and then in the constructor of House this is set m_peopleInside = new…
unknownSPY
  • 706
  • 4
  • 15
  • 27