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
-1
votes
2 answers

friend cannot access private variables?

class LongInt { friend ostream & operator <<(ostream & os, const LongInt & integer); ... } ostream & operator <<(ostream & os, LontInt & container) { os << container.number.size(); //error here return os; } error: 'std::vector…
OnTheFly
  • 2,059
  • 5
  • 26
  • 61
-1
votes
1 answer

using vector in ostream overload friend function

I have a template class called "KeyedCollection" that contains functions to insert data into a vector, as well as stream out the data. The vector is a private member function. I can't seem to figure out how to use the information from this vector in…
jordpw
  • 181
  • 2
  • 16
-1
votes
2 answers

C++ variable scope for class friends

I have: class Game... class D3DGraphics... I have a variable of type D3DGraphics called gfx declared in my Game class. I make another few classes: class Font... class Viewport... I make them both friends of D3DGraphics and declare variables…
Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
-1
votes
1 answer

Template and friend operator*

I have template Vector(my own template not STL). And i have problem with friend operator*. The problem is the results are ranodm number not the multiply of integer. #include #include using namespace std; template
Aku
  • 200
  • 3
  • 9
  • 17
-1
votes
1 answer

Post to friends timeline using the feed dialog example c# api

I am trying to post something on my friend's timeline and I keep on getting an error every time i try to do it. the code i am using is below. i wonder if the code is correct? Cause it doesn't work for me. Can you help? dynamic parameters = new…
-1
votes
2 answers

Echo to print one value at a time

I have created a system where a user signs up to my site, their details are entered into my users table (SQL). The user can then search for other users, via their username. They can then send a user a friend request, entered into my friendrequest…
-1
votes
1 answer

C++: granting member function friendship forward declaration?

I have a problem with friendship in c++. I have two classes, A and B, where the definition of B uses some instance of A. I also want to give a member function within B access to private data members in A, and so grant it friendship. But now, the…
-1
votes
2 answers

Friend of a derived class can access what variables?

To simplify my problem, I have something like this: class Base { private: protected: int a,b; string c; public: [some functions here] } class Derived : public Base{ [some variables and functions] friend void…
user1799323
  • 649
  • 8
  • 25
-1
votes
2 answers

I need a table for user posts (allowed to see only friend, specific persons etc.)

When user post a message, he can select: allowed to see only friend, specific persons etc.. mysql table: Post post_id post_nr user_id privacy option 1 1 2 allowed for friend id1 2 1 2 …
-1
votes
3 answers

STL list and friend classes - Don't get desired outcome

My intention is to store a list of B objects in class A, but I want a new element to be created in A list when I call B constructor. I have a code like this: class A {... protected: std::list Blist; std::list::iterator Bit; …
Adrián
  • 11
  • 2
-1
votes
1 answer

C++ - unable to set method friendship

I try to set friendship to method from class GameSimulator on Player class. for some reason I get error. GameSimulator.h: #ifndef GAMESIMULATOR_H_ #define GAMESIMULATOR_H_ #define NULL 0 #include "Player.h" class GameSimulator { public: void…
nimrod
  • 132
  • 1
  • 1
  • 8
-2
votes
1 answer

cpp - class that has pure virtual, normal function, static variables and friend class

Does it make sense to create a class which holds: pure virtual functions and also virtual functions and also regular methods and static functions and friend class declaration I'm asking from a "design practice" point of view. Without tiring you…
Yaniv G
  • 307
  • 4
  • 11
-2
votes
1 answer

Why is my friend function not working when put into a separate source code file in C++?

I have the following header file: TwoDimArray.h class TwoDimArray { int** data; int rows, cols; public: TwoDimArray(int, int); TwoDimArray(const TwoDimArray& orig); virtual ~TwoDimArray(); const TwoDimArray& operator=(const…
katie1245
  • 1,127
  • 8
  • 10
-2
votes
1 answer

Linker Error when calling operator<<, how to fix this?

Important Update: Removing the delegation of friend solved the problem Partially but why? and how may I keep it as friend... Why the following code gets me linker error? Dimensions dims2(3 ,14);//Fixed class 100% the bug isn't cause by…
user13742225
-2
votes
1 answer

Why can't friend function be recognized with using directive vs enclosing in namespace?

Why can't the friend operator<< be recognized when defined in the cpp file and a using directive? I have in header file, game.h namespace uiuc { class Game { public: Game(); void solve(); friend std::ostream & operator<<(std::ostream & os,…
heretoinfinity
  • 1,528
  • 3
  • 14
  • 33
1 2 3
99
100