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

non-class template has already been declared as a class template

I have cloned a project from GitHub which is implemented targeting Linux (using Linux specific socket) to use in windows with VC++. Have modified the needed part to match windows but compiling the singleton class I get the error which I have no clue…
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123
0
votes
1 answer

Is it possible to invoke an injected friend template function?

To be consistent with other (non-template) functions in a class I wanted to define and invoke a friend template function. I can define it with no problem (see function t below). namespace ns{ struct S{ void m() const{} friend void f(S…
alfC
  • 14,261
  • 4
  • 67
  • 118
0
votes
1 answer

C++ Accessing an element of a private array from a friend function (operator <<)

I've got a class with the following declaration and accompanying definition: friend ostream& operator<<(ostream& out, const Poly& poly); ostream& operator<<(ostream& out, const Poly& poly) {} and private: int *polyArray; Inside the code for…
Tyler M.
  • 115
  • 1
  • 1
  • 11
0
votes
2 answers

Problem using Friend function in QT

I wish to add items in a ListWidget, which is a private member of a class, through a friend function. Actually, i am trying this sample snippet to use friend function for more classes to update their ListWidgets from a single function. I need…
dipeshtech
  • 384
  • 1
  • 5
  • 16
0
votes
0 answers

Declaring an overloaded function in global namespace as friend of template class

My issue is simple. I am able to declare an overloaded function in the global namespace as a friend of a template class in a nested namespace using fundamental types, however if I change the definition and declaration of the function to return…
0
votes
1 answer

How a write a global non member post decremented overloaded operator?

I am beginning to programming. I am stuck in this point so I hope you guys will help me. When we write a post decrement member function the syntax for that is type type::operator--(int){} But I want this to be a friend function so how can i…
Hamza
  • 82
  • 9
0
votes
1 answer

Inheriting private CRTP constructor using friend declaration

I have problems understanding the correct behavior of inheriting constructors from a base class. In my particular case, I have a crtp-base class with private constructors in order to prevent an instantiation of the base class (as abstract…
0
votes
1 answer

How do I declare a friend function for a class?

Off-Topic: I want to ask, is this the right place to ask this kind of question? What would be a more appropriate place to ask this kind of "naive" questions? I would like a website or something. Thank you. Now my problem: I have the task to write…
0
votes
2 answers

MSBuild fails to build C++/CLI friend assemblies

I have Visual Studio 2008 SP1, two C++/CLI projects, lets say proj1 and proj2. proj2 is dependent on proj1, but in a weird way (see below). In Project Dependencies I specify that proj2 depends on proj1. Also proj2 references include proj1. Then I…
vlad2135
  • 1,556
  • 12
  • 14
0
votes
1 answer

How do I declare std::pair as a friend so it sees private default ctor

I am using boost (de)serialization to reconstruct classes without public default ctors, by design. I declare a private default ctor and declare the boost access class as a friend, and it uses the default ctor as part of its deserialization process.…
user1414050
  • 99
  • 1
  • 2
0
votes
4 answers

Friend function cannot access private data member (c++)

I have searched many different questions and could not find a solution that matched my specific problem. I have this header file for a queue: #ifndef HEADERFILE #define HEADERFILE #include #include using namespace…
0
votes
1 answer

friend function of a template class that has different template parameters as input

I have class for floating point format where the size of the mantissa and the exponent can be specified as a template parameter: template class fpxx { public: const int exp_size = _exp_size; const int…
Tom Verbeure
  • 232
  • 2
  • 8
0
votes
1 answer

friends not showing up in GameKit sandbox

I am perplexed by a behaviour I am getting in the GameKit sandbox. It worked very nicely in joining two devices (an iPhone and an iPad) some weeks ago, and those devices still work with one another smoothly. I have tried to add a new friend on a…
0
votes
2 answers

Classes and a friend function between them

I am learning class and friend function. I want the function eat() from the class Farm to access the variable price from the class Bull and change the price value. So I need to implement a friend function. I have problem to use function as I do not…
ripeisripe
  • 69
  • 8
0
votes
4 answers

Encapsulation in a Composition Class C++

I have a map class, which contains a vector containing MapEntitys. MapEntity is a class of which Factory, Farm and 3 other classes are inherited from. These 5 classes both should be "ticked" every few seconds, at which point they will all do a…
Ell
  • 4,238
  • 6
  • 34
  • 60