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

Restricted class factory design pattern

Is there an elegant (or any) way to achieve following in C#? Let's have a class ItemBase (further derivable to Item1, Item2...), which does not allow direct instantiation (non-public construction) - to prevent user to create any 'untracked'…
sharpener
  • 1,383
  • 11
  • 22
0
votes
2 answers

Use of `friend` in self contained program?

I have a large, self-contained environmental model. In the model I have a large class called cell, that contains many (~100) vectors and doubles that all together dictate the current state of the cell across many attributes. These attributes are…
traggatmot
  • 1,423
  • 5
  • 26
  • 51
0
votes
1 answer

Use of friend as "namespace-private" fields or methods

I have a question which is basically the quite opposite of this one. As we can see in this post, Java does have one more access mode than C++ : package one. In my code, I would like to make a class that only some other class could instantiate and…
Aracthor
  • 5,757
  • 6
  • 31
  • 59
0
votes
4 answers

Friend function is not accessing private members of another friend class

I have two classes Term and Polynomial. Polynomial class is declared to be a friend of Term class. Polynomial class has friend function in it. When i implement that function in a cpp file of Polynomial class, the private members of Term are not…
R32
  • 9
  • 1
  • 4
0
votes
3 answers

Friend Function can't see private member

I've tried to figure this out for an hour now and I've gotten nowhere. I have a class with a friend function and private members but I am getting a compiler error telling me that I cannot access a private member using that friend function. line 36…
0
votes
1 answer

Linking "Friends" with the account holders profile

I am designing an application where an account holder has "friends". How would I go about linking those friends to the original account holder? Would an efficient SQL table be something like: AccountHolderID (varChar 20) FriendsID (nText)
user279521
  • 4,779
  • 21
  • 78
  • 109
0
votes
0 answers

argument list for class template Vec2 is missing

I am defining a Vec2 class with a friend functions. I am getting the error: argument list for class template Vec2 is missing for the friend function: friend Vec2 operator * (const T &r, const Vec2 &v). template class Vec2 …
0
votes
2 answers

How to overload an operator with a friend function in a generic class?

I have written a matrix class. I have overloaded the operator+, so that the user can write: matrix + 2. I would like the user to also write: 2 + matrix. For the standard format (i.e. the object invoking 2) I have written a standard operator…
Ryan J. Shrott
  • 592
  • 1
  • 8
  • 26
0
votes
1 answer

Dependency in template friend of template class

After hours of trying to find out this syntax by reading the standart I gave up on trying to understand this. I have a template class with a template constructor I need to partially specialize, since this is impossible I wrapped the constructor…
Omer Rosler
  • 237
  • 1
  • 10
0
votes
1 answer

Creating and using func pointer to method of friend class

I have 2 classes: enum class Enumtype { typ1, typ2, }; class A { private: retType Func1(arg1Type, arg2Type, arg3Type); retType Func2(arg1Type, arg2Type, arg3Type); public: A(); retType Func(Enumtype, arg1Type, arg2Type,…
MKK
  • 130
  • 10
0
votes
1 answer

Operation with 2 friends constructor

I created two classes and a constructor in each. Type followed a new class and constructors friends functions of the classes before. #include using namespace std; class clsAtmosfericConditions; class clsDensity{ float…
0
votes
3 answers

Numeric Array Class: Multiplication using friend functions

I have been trying to solve this bug for days. I made a generic array class, from which I used generic inheritance to create a numeric array. Everything works perfect; however, I am having trouble with multiplication/scaling of the numeric array. I…
Ryan J. Shrott
  • 592
  • 1
  • 8
  • 26
0
votes
0 answers

Lambda expressions (C++0x) not working in C++/CLI?

If I write this std::function myFunction = []() {return 42;}; in C++/CLI under VS2010 (in an MSTest unit test class, in case it matters), I get the compiler error C3809: a managed type cannot have any friend functions/classes/interfaces. Is…
Robin
  • 518
  • 3
  • 13
0
votes
1 answer

Calling Protected Function From Derived Friend Function

I have a base class, Animal, and a derived class, Lion. Animal has a protected function called eat(). I would like to call eat() from a friend function defined in Lion, but when it won't compile: error: call to non-static member function without an…
AndrewCox
  • 1,044
  • 7
  • 14
0
votes
3 answers

cannot access private members in friend ostream

I tried to make friend ostream function. The compiler say i cannot access private member of the class, even though i declared it as friend. I read a similar question and it say the problem is with the namespcaes.(the question: C++ friend function…