friend

friend class/function in c++

I see a lot of people recommending a function/class to be made a friend of another class here in SO though there are other alternatives. Shouldn't friend be sparingly used in C++? I feel other options must be considered before deciding on using the friend feature. Opinions/suggestions are welcome. ...

Restrict inheritance to desired number of classes at compile-time

We have a restriction that a class cannot act as a base-class for more than 7 classes. Is there a way to enforce the above rule at compile-time? I am aware of Andrew Koenig's Usable_Lock technique to prevent a class from being inherited but it would fail only when we try to instantiate the class. Can this not be done when deriving itse...

Is it possible to narrow the friend relationship between classes and functions when multiple template types are involved?

Suppose I represent an image class as: template <typename Pixel> class Image { ... }; I would need my own swap function to prevent extra copying of images, so I would need to make it a friend of Image. If inside Image I write: template <typename T> friend void swap(Image<T>&, Image<T>&); I get what I want, but it makes all swap fu...

How to access a data class's private member variable from another derived class whose parent class is a friend class of the data class?

I have three classes: A data holder class CDataHolder, which uses a Pimpl pattern class CDataHolder { public: // ... private: friend class CBase; struct PImpl; PImpl* iPimpl; }; A base class CBase, which need to access the iPImpl member in CDataHolder, so it is a friend class of CDataHolder class CBase: { protected: CDataHolde...

How to allow template function to have friend(-like) access?

How does one modify the following code to allow template function ask_runUI() to use s_EOF without making s_EOF public? #include <string> #include <iostream> #include <sstream> #include <vector> class AskBase { protected: std::string m_prompt; std::string m_answer; virtual bool validate(std::string a_response) = 0; public: ...

Why can't I befriend a template parameter?

When researching an answer to a question (based on this answer) I tried to do the following: template <class T> class friendly { friend class T; }; friendly<string> howdy; This fails to compile with the following error: error: template parameter "T" may not be used in an elaborated type specifier frien...

How does the friend keyword (Class/Function) break encapsulation in C++?

Some programmer said that, "a friend function break the encapsulation in C++". and some programmer also said, "Friend functions do not break encapsulation; instead they naturally extend the encapsulation barrier" what does it mean?.. If a friend function breaks the encapsulation in C++ then how?? ...

Google Friend Connect

I want to get the google friend connect logged in user's email address from my website. I already implement the GFC in my website. please give any suggestion? ...

Help eliminating friends/internals

I often see people say things like "if you need friend/internal then your design is wrong", could someone tell me how to redesign the following code to eliminate the internal in ChessPiece.Location? It's currently used so that adding a piece to ChessBoard sets the ChessPiece.Location property to match, obviously making it public would b...

Friend functions

For the example under Friend Functions How is the following true? "Notice that neither in the declaration of duplicate() nor in its later use in main() have we considered duplicate a member of class CRectangle. It isn't! It simply has access to its private and protected members without being a member." Duplicate is declared in the publ...

Template friendship

I'm trying to access protected variables of a template class with different template parameters. A friend declaration with template parameters is giving the following error: multiple template parameter lists are not allowed My code is template<class O_, class P_> class MyClass { //multiple template parameter lists are not allowed...

XML Serialize Friend Classes in VB.net

I have a few classes (about 15 or so) in VB.net (2005) that I would like to be able to serialize to xml. Unfortunately they are labeled as friend classes and cannot be exposed outside of the assembly. The assembly is a dll that is a com interop plugin to a CAD system. I have set all of my classes as friends so that they are not exposed ...

Friend class and all its descendants

Hello, suppose that I have a class A with several subclasses (B, C, and D). I need B C and D to access some protected members from a class E. Is it possible to make B, C and D friends of E in a single hit without having to list them all? I have tried with: class E { friend class A; ... }; But this doesn't work. Thank you...

What is "AllInternalsVisible" parameter of assembly:InternalsVisibleTo attribute?

Hi, My intellisense is coming up with a boolean named parameter "AllInternalsVisible=" in an [assembly:InternalsVisibleTo("AssemblyName")] declaration. Just position the cursor after the second double-quote and hit Ctrl-space. What is that - I cannot find any documentation on MSDN about that. I am using VS2005 and .Net 2.0. As a ...

pimpl idiom and template class friend

I'm trying to use the pimpl idiom to hide some grungy template code, but I can't give derived classes of the body class friend access to the handle class. I get an error C2248 from MSVC 9 sp1. Here's some code to duplicate the error: // // interface.hpp // namespace internal{ template<class T> class specific_body; } class int...

FBML multi friend selector in fb:dialog

Hey Guys, Is there a way to show the multi friend selector widget (fb:multi-friend-selector) in an fb:dialog? I have a button, on selecting which I would like to show the friend selector popup and users can send invite to their friends. I got the friend selector working on the main page but have no clue on how to display that widget i...

Erasing a vector element by key

ive defined the following and filled it with elements: vector <vector<double> > my_vector; but i want a delete an element with a specific key... my_vector.erase(int(specific_key)); but it doesnt allow me. how would i properly dispose of the elements assigned to that key properly? ...

How to get the name of a Facebook friend?

Hi, I'm just playing around with the Facebook API in C# (Windows Form App), and I'm struggling to figure out how to get the name of a selected friend. I already have the uid for that friend using the following code: IList<long> myFreinds = fs.Friends.Get(); for (int i = 0; i < myFreinds.Count; i++) { string friendName = ""; //this i...

friend function declared inside befriended class, GCC does not compile

Hello, I've got following code: File: Foo.h class Foo { friend void Bar(); }; File: Foo.cpp void Bar() {}; File Test.cpp #include "Foo.h" int main(void) { Bar(); return 0; } VS2008 compiles this without any error or warning. G++ 4.3.4 reports: test.cpp: In function ‘int main()’: test.cpp:8: error: ‘Bar’ was not d...

Using the same key for signing multiple assemblies: wise/unwise?

It's possible to use the same strong name key for multiple related projects/assemblies. I'm interested to know whether there are any drawbacks to using this approach. SPecifically, can it lead to a lack of security? One area I'm thinking about this is in the use of the friend assemblies. ...