friend

Appropriate use of friend? Container class designed to manipulate objects of specific type

Lets say you have a FooManager made to manage multiple objects of type Foo. The FooManager needs to see some parts of its Foos to evaluate their current state. Before I was using a few accessors in Foo to see these parts, until I realized that FooManager is the only class actually using these. I decided to make FooManager a friend of Foo...

Template friend

I'd like to do the following: template <typename T> struct foo { template <typename S> friend struct foo<S>; private: // ... }; but my compiler (VC8) chokes on it: error C3857: 'foo<T>': multiple template parameter lists are not allowed I'd like to have all possible instantiations of template struct foo friends of foo<...

Template friend and nested classes

Hello, please consider the following code: template <typename T> struct foo { template <typename S> struct bar { template <typename> friend struct bar; }; }; I'd like all instantiations of foo<T>::bar to be friends of foo<T>::bar<S> for any S. If bar is not a nested template, the syntax above works just fine. B...

Why can't I declare a friend in one class that is a private member of another class?

Given the following code: class Screen; class WindowMgr { WindowMgr& relocateScreen( int r, int c, Screen& s); }; class Screen { friend WindowMgr& WindowMgr::relocateScreen( int r, int c, Screen& s); // ^ cannot access private member declared in class 'WindowMgr' int m_nR, m_nC; }; WindowMgr& WindowMgr::reloc...

c++ friend function - operator overloading istream >>

Hello all, My question is in regards to friend functions as well as overloading the << and >>. From my understanding I thought friend functions could (and should) access private member variables directly. However in the case I have here the compiler would only accept my .cxx file when I used "get" functions to obtain each private variab...

Can derived class use friend function of the basis class?

Hello, If I have some class Basis, and derived from it Derived, inside basis I have friend function friend int operator!=(const Basis&, const Basis&) Inside derived class I don't have such function So my question is if I have inside my main If( derived1 != derived2 ) ... why does it work? i don't have any constructor for casting f...

How to name this key-oriented access-protection pattern?

Apparently this key-oriented access-protection pattern: class SomeKey { friend class Foo; SomeKey() {} // possibly non-copyable too }; class Bar { public: void protectedMethod(SomeKey); // only friends of SomeKey have access }; ... doesn't have a known name yet, thus i'd like to find a good one for it so we can refe...

Can we increase the re-usability of this key-oriented access-protection pattern?

Can we increase the re-usability for this key-oriented access-protection pattern: class SomeKey { friend class Foo; // more friends... ? SomeKey() {} // possibly non-copyable too }; class Bar { public: void protectedMethod(SomeKey); // only friends of SomeKey have access }; To avoid continued misunderstandings, ...

How to make boost::make_shared a friend of my class.

I have written a class with protected constructor, so that new instances can only be produced with a static create() function which returns shared_ptr's to my class. To provide efficient allocation I'd like to use boost::make_shared inside the create function, however the compiler complains that my class constructor is protected inside b...

How to fetch facebook friends email adress

I tried hard, but I think isn't possible but yahoo is capable to import all'your contact information. How that works? ...

Friend function and templates

My question is related to this question. #include<iostream> template< typename T > class T1 { public: T i; void display() { std::cout<<i<<"\n"<<j<<"\n"<<k; } protected: T j; private: T k; friend void Test( T1 &obj); }; template<typename T> void Test(T1<T> &obj) { T a=T(); obj.i=a; obj.j=a; ...

Template classes and the friend keyword in c++ (specific example refers to boost::multi_index)

so you have a class employee class employee { public: employee(const string &name, int id) : m_name(name) , m_id(id) {} const string &getName() const { return m_name; } int getID() const { return m_id; } private: string &m_name; int m_id; }; and you have private data members for encapsulation. But now you want to...

Templated << friend not working when in interrelationship with other templated union types.

While working on my basic vector library, I've been trying to use a nice syntax for swizzle-based printing. The problem occurs when attempting to print a swizzle of a different dimension than the vector in question. In GCC 4.0, I originally had the friend << overloaded functions (with a body, even though it duplicated code) for every dim...

C++ Accessing a friends class->member->public method?

Is the following code legal in C++. Accessing a friend class member public method? I know this sounds confusing, and the best way to show it is in code. I was wondering if the TestClassC::Method() is valid in the code below? I've compiled (g++) and it works, however, I run into a situation, where it produces a segmentation fault on othe...

C++ friend comparison between two instantiations of one class template

I am trying to write a class template that provides a comparison operator between two instatiations with different template types. As is often the case, this operator is a non-member friend. A simplified example of what I am trying to achieve can be seen below. template<typename T> class Wrapper { // Base type, which must have a val()...

Why does C++ not allow inherited friendship?

Why is friendship not at least optionally inheritable in C++? I understand transitivity and reflexivity being forbidden for obvious reasons (I say this only to head off simple FAQ quote answers), but the lack of something along the lines of virtual friend class Foo; puzzles me. Does anyone know the historical background behind this dec...

Befriending a class

I am trying to befriend a class in order for it to be able to reach a private constructor of it. In some_file.h class B; namespace some_name { class A { public: A() {} private: A (int x) {} friend class ::B; }; } In other_file.h #include "some_file" namespace { class B { protected: A* get_a(int x) { retur...

Google Friend Connect fcauth cookie in php

Hi folks, this may be easy for most of you .. but not me. I am using some "sample" Google code - as it fits my purpose so why change what works - but for the life of me I cannot access/find/get etc the FCAuth cookie after a user is logged in. Help please - thanks in advance. Here is my code (the Site ID is in a set variable, and all t...

Friend access to protected nested class

I have the following C++ code: class A { protected: struct Nested { int x; }; }; class B: public A { friend class C; }; class C { void m1() { B::Nested n; // or A::Nested } }; Compiling this snippet with g++ 4.4, it does not make a difference whether I use B::Nested or A::Nested in m1. Clang accepts B::Nested, but...

Calling friend function defined in struct requires forward declaration?

While reading Karlsson's Beyond the C++ Standard the author defined the friend function intrusive_ptr_add_ref in the body of class reference_counted (see pg 36). That function is called automatically using Argument Dependent Lookup at the proper time. Never having seen friend functions defined in the body of a class, I played around an...