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.
...
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...
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...
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 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:
...
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...
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??
...
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?
...
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...
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...
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...
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 ...
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...
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 ...
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...
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...
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?
...
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...
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...
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.
...