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

Is it possible for a friend function to create new object? C++

Hello I am trying to make little simulation of school system. I am wondering if I have 2 classes: 1: Principal 2: Teacher then is it possible for method from class Principal to create new object of class Teacher? Here's what I would like to do…
MeIsNoob
  • 69
  • 2
  • 5
0
votes
1 answer

c++ friend inheritance

I understand that friend is not inherited. I have classes Parent Person Child. Parent and Person are friends of each other. Parent has the following PROTECTED function... class Person { friend class Parent; public: Parent *…
Joshua
  • 1,516
  • 2
  • 22
  • 31
0
votes
1 answer

friend of template method in template class, within a template class

The description can be quite mind boggling so I get straight to the example: #include #include using namespace std; template class fr{ static void privatestuff(){ cout<<"private of…
Lorenzo Pistone
  • 5,028
  • 3
  • 34
  • 65
0
votes
1 answer

error while copying std::map defined in a class

I have a class with a std::map used as a container. I want to add a function to copy the map between two objects. Since the map was declared as a private member of the class, I need a friend function to do so. Here is my code: class Data; void…
user1285419
  • 2,183
  • 7
  • 48
  • 70
-1
votes
1 answer

Sending message to a friend on facebook Android

I am developing an application which is able to let a user send a message to a friend on facebook. I have looked at Facebook API, Hackbook folder. I used the following code, but it did not work. It seems to ask me to implement a new dialog for it.…
sophors
  • 31
  • 1
  • 5
-1
votes
2 answers

Differing access on a member of a class according to the context

Let's say I have a class MainApp using methods of a dynamic library via an interface FrontEnd FrontEnd uses internally instances of a class Data (contained in a class BackEnd) This class Data only contains a member and its accessor, no public method…
codablank
  • 181
  • 2
  • 9
-1
votes
1 answer

Why C++ friendship for function inside a class does not work same as a standalone function?

I want to know why one of the following two codes compiles while the other does not. In the first code, createB is a stand alone function. In the second code the function createB is a member of class A. The first one compiles. #include…
user27665
  • 673
  • 7
  • 27
-1
votes
1 answer

`friend struct std::is_invocable` can't access private members of class it is friend to

I have made struct std::is_invocable be a friend of class D, but it is unable to access the private member of D. This happens with gcc, clang, and MS Visual Studio 2017, so it is not one of MSVC's quirks. #include #include…
TRPh
  • 187
  • 1
  • 9
-1
votes
2 answers

Implementing operator<< in C++ template class

I am having a compiler error implementing operator<< on a C++ template class. Here is the code: #pragma once #include using namespace std; //a template class to process a pair of "things" template class Pair { private: T…
-1
votes
1 answer

User defined defined manipulator error: "not declared in this scope"?

I have tried many ways to figure out this error, but still I am a beginner and can't figure it out. I have done exactly as in my handout. We are required to show an output of a matrix but due to some error my program is getting stuck. It says that,…
Abeer Naz
  • 1
  • 1
-1
votes
1 answer

what will happen is c++ discard friend keyword?

I am confused on friend function and friend class in c++. and in my coding experience, i never used friend. and even not found others's code contains friend. i know the basic usage and idea of friend. and typical demo is like: #include…
xyhuang
  • 414
  • 3
  • 11
-1
votes
1 answer

array from friend class in assignment operation is being manipulated

I have a class called Map with the following declaration: class Map { public: void get_world_size(const double val); void get_landmarks(const double array[][2], int val); void print_map(); private: int num_landmarks; double…
Atta Oveisi
  • 21
  • 2
  • 8
-1
votes
1 answer

My global function cannot access the private data member, even after using friend function

Cannot access the private member 'b'. This was a test problem and I can only edit a limited number of lines. This was a simple addition program, with the 3 lines highlighted by '//' left empty, this was my solution to the problem. But I am facing…
-1
votes
1 answer

C++ QT Event: Access outer class' private variables from inner nested class

Below is a working C++ QT code that simply displays an image with mouse events. To implement the events, I nested a custom QGraphicsPixmapItem class within my MainWindow class. The problem I am having is accessing and modifying the private…
Alec Mitchell
  • 53
  • 1
  • 6
-1
votes
1 answer

gtest: Make base test class friend of the test class

I have the following constructs in my test: class FooType {}; class OtherFooType {}; using FooTypes = ::testing::Types; TYPED_TEST_CASE(FooTest, FooTypes); template class FooTest : public…
gruszczy
  • 40,948
  • 31
  • 128
  • 181