friend Questions
4
Solved
I want to make class A friend of class B. I want to do this as these interact very much and A needs to change internals of class B (which I don't want to expose using public). But I want to make su...
Equinox asked 22/10, 2009 at 19:34
5
Solved
I heard there is a possibility to enable google-test TestCase classes friends to my classes, thus enabling tests to access my private/protected members.
How to accomplish that?
Madgemadhouse asked 7/3, 2010 at 13:22
4
Solved
Discussion
I know that main can be a friend of a class:
#include <iostream>
class foo {
friend int main();
int i = 4;
};
int main() {
foo obj;
std::cout << obj.i << std::e...
Publias asked 31/7, 2014 at 22:33
2
I'm trying to use variadic templates to specify friend classes. I try with the following syntax, but it doesn't work.
template <class... Args>
struct A {
friend Args...;
};
I try to code ...
Ganof asked 26/4, 2014 at 2:40
6
Is it not supposed for a friend function to be explicitly defined outside of a class ?
If so why can i declare a friend function inside a class definition just like any member function ?
What is th...
Teliospore asked 7/7, 2013 at 13:25
5
Solved
Is there some equivalent of "friend" or "internal" in php? If not, is there any pattern to follow to achieve this behavior?
Edit:
Sorry, but standard Php isn't what I'm looking for. I'm looking f...
3
Solved
I always thought that aggregate initialization was to save coders from writing custom constructors. However, this seems to have "sneaked in" a "security by-pass" for private con...
Trant asked 5/1, 2021 at 14:23
2
Solved
class Base {
public:
class FirstBase {
friend class Base;
int x = 10;
};
class SecondBase : public FirstBase {
public:
SecondBase() : FirstBase() {}
void t() { std::cout << FirstBas...
Livraison asked 14/8, 2023 at 11:27
2
Solved
I'm still a beginner in C++ trying to learn more about the language. I recently read about the concept of ADL (Argument-Dependent Lookup) and Hidden Friends idiom (https://www.modernescpp.com/index...
8
Solved
According to the C++ Primer book, the author mentioned that we can specify a class member function as a friend of another class, instead of the entire class (page 634).
Then, I tested this code:
cl...
9
Solved
Suppose I have three C++ classes FooA, FooB and FooC.
FooA has an member function named Hello, I want to call this function in class FooB, but I don't want class FooC be able to call it. The best ...
2
Solved
Context: To our surprise, MSVC with C++20 mode and two-phase compliance enabled accepts the following code:
template<class T>
class X
{
friend int foo<X>(X x);
int a = 10;
};
templa...
Tuff asked 3/8, 2022 at 11:2
1
Solved
There used to be a paragraph in the standard which stated that
the names of a namespace-scope friend functions of a class template specialization are not visible during an ordinary lookup unless e...
Carreno asked 17/2, 2022 at 10:8
1
I know the general use cases for the friend keyword with regards to encapsulation but one a couple of occasions, I have needed the friend keyword just to "get the job done". These use cas...
Christology asked 20/12, 2021 at 6:43
4
Solved
Someone can explain me a warning from g++ ?
Given the following code
#include <iostream>
namespace foo
{
struct bar
{ friend std::ostream & operator<< (std::ostream &, bar...
Sarong asked 25/6, 2017 at 19:37
1
Solved
In the next example the class U with private destructor has a friend function foo. And this friend function has argument of type U with default value U{}:
class U{ ~U(); friend void foo(U); };
void...
Karakorum asked 9/8, 2021 at 19:2
1
Solved
Following the Czech song from Eurovision 2019 in Tel-Aviv
It is known that in C++ a friend of a friend is not (automatically) a friend.
Clang however differs on the following code with GCC and MSVC...
Swashbuckling asked 28/5, 2021 at 15:26
3
Solved
Im trying to define a class friend function outside the namespace like this:
namespace A
{
class window
{
private:
int a;
friend void f(window);
};
}
void f(A::window rhs)
{
cout << rh...
Goodin asked 7/6, 2012 at 14:50
2
I'm having a class which needs to have multiple overloads of the * operator. Some of these need to be declared as friends so I can have the class type as second argument. This is an example of a cl...
Guatemala asked 19/5, 2021 at 21:5
4
Solved
Is there any way to make certain variables in classes "private" (or whatever self.__var really is) but be accessible to another class, like friends in c++, except in python? I do not want the varia...
Archdeacon asked 14/6, 2011 at 3:51
4
Solved
Is there a difference between declaring a friend function/class as private or public? I can't seem to find anything about this online.
I mean the difference between:
class A
{
public:
friend c...
1
Solved
Suppose we have a class foo from a namespace space which declares a friend function named bar, which is later on defined, like so:
namespace space {
struct foo {
friend void bar(foo);
};
}
name...
Chiu asked 9/5, 2021 at 16:23
5
Solved
In The C++ Programming Language, Fourth Edition - chapter 23.4.7 Friends, I found following example (I have slightly modified it to show only relevant part):
template<typename T>
class Vecto...
1
I have found a situation where code compiles successfully under C++17, but FAILS under C++20.
This blocks us from upgrading our existing code design to the newer standard.
Why doesn't this compile ...
Decretive asked 18/3, 2021 at 4:2
4
I am trying to relearn C++ after taking an intro course a few years ago and I’m having some basic problems. My current problem occurs when trying to use a friend function. Here is my code in 2 file...
Sherwood asked 28/7, 2013 at 3:14
1 Next >
© 2022 - 2025 — McMap. All rights reserved.