friend

c++ friend function - operator overloading istream >>

≯℡__Kan透↙ 提交于 2019-11-29 06:09:36
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 variable. Here is my header file class BigNum public: // CONSTRUCTORS and DESTRUCTORS BigNum(); BigNum(int num, size_t optional_base = 10); BigNum(const char strin[], size_t optional_base = 10); // MEMBER FUNCTIONS size_t get_digit(size_t index) const; size_t get_used() const;

How to send friend request using Facebook dialogs on Android?

怎甘沉沦 提交于 2019-11-29 05:13:47
I want tot send a friend request using the Facebook Android SDK. I'm currently using this code (which I got from here ): Bundle parameters = new Bundle(); parameters.putString("APP_ID","USERNAME"); facebook.dialog(this, "friends", parameters, this); where APP_ID is the Facebook ID of my app and USERNAME is the username of the friend I want to add. This leads to the following error: API Error Code:100 Invalid parameter The parameter id is required I thought the id parameter meant the APP_ID. I have gone through the relevant documentation regarding dialogs at http://developers.facebook.com/docs

Is ADL the only way to call a friend inline function?

江枫思渺然 提交于 2019-11-28 22:56:22
Let us define f , as a friend function of S , inside the declaration of S : struct S { friend void f() {} }; I cannot find a way to call f . Is it true, then, that such an inline friend function can only be called with argument-dependant lookup ? struct S { friend void f() {} friend void g(S const&) {} } const s; int main() { // f(); // error: 'f' was not declared in this scope // S::f(); // error: 'f' is not a member of 'S' g(s); // S::g(s); // error: 'g' is not a member of 'S' } Bonus: what if I want to get a function-pointer/ std::function /lambda to g ? Is it true, then, that such an

C++ friend inheritance?

时光毁灭记忆、已成空白 提交于 2019-11-28 22:33:23
Does a subclass inherit, the main class' friend associations (both the main class' own and other classes friended with the main class)? Or to put it differently, how does inheritance apply to the friend keyword? To expand: And if not, is there any way to inherit friendship? I have followed Jon's suggestion to post up the design problem: C++ class design questions Friendship is not inherited in C++. The standard says (ISO/IEC 14882:2003, section 11.4.8): Friendship is neither inherited nor transitive. friend only applies to the class you explicitly make it friend and no other class. http://www

What is the fully qualified name of a friend function defined inside of a class?

六月ゝ 毕业季﹏ 提交于 2019-11-28 20:03:43
What is the fully qualified name of a friend function defined inside of a class? I recently saw an example analogous to the following. What is the fully qualified name of val() below? #include <iostream> namespace foo { class A { int x; public: A(int x = 0) : x(x) { } friend int val(const A &a) { return a.x; } }; } int main() { foo::A a(42); // val() found using ADL: std::cout << val(a) << std::endl; // foo::val(a); // error: 'val' is not a member of 'foo' // foo::A::val(a); // error: 'val' is not a member of 'foo::A' return 0; } Is argument-dependent lookup the only way val() can be found?

Allowing a “friend” class to access only some private members

让人想犯罪 __ 提交于 2019-11-28 19:49:17
问题 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 way I can figure out to realize this is to declare FooB as a friend class of FooA. But as long as I do this, all FooA's private and protected members will be exposed which is quite unacceptable to me. So, I wanna know if there is any mechanism in C++(03 or 11) better than friend class which can

When to use friend class in C++ [duplicate]

99封情书 提交于 2019-11-28 19:42:11
问题 Possible Duplicate: When should you use 'friend' in C++? I was brushing up on my C++ (I'm a Java developer) and I came across the friend class keyword which I had forgotten about for a while. Is this one of those features that's just part of the kitchen sink, or is there a good reason for doing this rather than just a vanilla getter? I understand the difference in that it limits who can access the data, but I can't think of a scenario when this would be necessary. Note: I've seen a similar

public friend swap member function

只谈情不闲聊 提交于 2019-11-28 14:55:50
In the beautiful answer to the copy-and-swap-idiom there is a piece of code I need a bit of help: class dumb_array { public: // ... friend void swap(dumb_array& first, dumb_array& second) // nothrow { using std::swap; swap(first.mSize, second.mSize); swap(first.mArray, second.mArray); } // ... }; and he adds a note There are other claims that we should specialize std::swap for our type, provide an in-class swap along-side a free-function swap, etc. But this is all unnecessary: any proper use of swap will be through an unqualified call, and our function will be found through ADL. One function

cannot access private members in friend ostream

一世执手 提交于 2019-11-28 12:11:35
问题 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 can't access private members) My Code is below: header: #include <iostream> #include <string> //using namespace std; namespace biumath { #ifndef BIUMATH_H #define BIUMATH_H class Assignment { private: int **m_varArray; int m_rowsOfVarArray; public:

'Friends' equivalent for Java? [duplicate]

大憨熊 提交于 2019-11-28 09:39:07
having a little architectural trouble here. In C++, we have the notion of 'friends,' where such friend classes can access private members. So, I'm deving a Java app and trying to adhere to the MVC architecture. I've got a controller class that manages graph connectivity between 'map_objects.' I'd like to hide the function in the DTO 'map_objects' that actuall sets up these connectivities, by using this controller class. (Ie, even if the controller class implements the required functionality of setting up connectivities, the 'users' can still access setter/getter functions in the the DTO