friend

Are friend functions inherited? and why would a base class FRIEND function work on a derived class object?

ぐ巨炮叔叔 提交于 2020-01-16 05:26:27
问题 class baseClass { public: friend int friendFuncReturn(baseClass &obj) { return obj.baseInt; } baseClass(int x) : baseInt(x) {} private: int baseInt; }; class derivedClass : public baseClass { public: derivedClass(int x, int y) : baseClass(x), derivedInt(y) {} private: int derivedInt; }; in the function friend int friendFuncReturn(baseClass &obj) { return obj.baseInt; } I don't understand why would the friend function of the base class work for the derived class? should not passing derived

tableView折叠

99封情书 提交于 2020-01-16 02:21:42
#import <UIKit/UIKit.h> @class CZFriendGroup; @class CZHeaderView; @protocol CZHeaderViewDelegate <NSObject> @optional - (void)headerViewDidClickedNameView:(CZHeaderView *)headerView; @end @interface CZHeaderView : UITableViewHeaderFooterView @property (nonatomic, strong) CZFriendGroup *friendGroup; @property (nonatomic, weak) id<CZHeaderViewDelegate> delegate; + (instancetype)headerViewWithTableView:(UITableView *)tableView; @end #import "CZHeaderView.h" #import "CZFriendGroup.h" @interface CZHeaderView () @property (nonatomic, weak) UIButton *nameView; @property (nonatomic, weak) UILabel

C++ friend function hidden by class function?

Deadly 提交于 2020-01-13 08:22:13
问题 Minimal example: class A { friend void swap(A& first, A& second) {} void swap(A& other) {} void call_swap(A& other) { swap(*this, other); } }; int main() { return 0; } g++ 4.7 says: friend.cpp: In member function ‘void A::call_swap(A&)’: friend.cpp:7:20: error: no matching function for call to ‘A::swap(A&, A&)’ friend.cpp:7:20: note: candidate is: friend.cpp:4:7: note: void A::swap(A&) friend.cpp:4:7: note: candidate expects 1 argument, 2 provided Outcomment line 4: // void swap(A& other) {}

templated friend function lookup

∥☆過路亽.° 提交于 2020-01-11 09:25:08
问题 The following simple code compiles fine class A { int x[3]; public: A() { x[0]=1; x[1]=2; x[2]=3; } friend int const&at(A const&a, unsigned i) noexcept { return a.x[i]; } friend int foo(A const&a, unsigned i) noexcept { int tmp = at(a,i); return tmp*tmp; } }; but if the friends are made templates class A { int x[3]; public: A() { x[0]=1; x[1]=2; x[2]=3; } template<unsigned I> friend int const&at(A const&a) noexcept { static_assert(I<3,"array boundary exceeded"); return a.x[I]; } template

Overload operator<< for nested class template

寵の児 提交于 2020-01-11 08:51:09
问题 I have the following setup: template< class T > struct Foo { struct Bar { Bar ( const T &t ) : otherT_( t ) {} T otherT_; }; Foo ( const T &t ) : myT_( t ) {} T myT_; }; Now, I want to make instances of Foo< T >::Bar streamable to std::cout and friends. I tried this: template< class T > std::ostream& operator<< ( std::ostream &os, const typename Foo< T >::Bar &bar ) { os << "<bar: " << bar.otherT_ << ">"; return os; } But the following code does not compile: Foo< int > foo( 5 ); Foo< int >:

C++ friend function can't access private members

╄→尐↘猪︶ㄣ 提交于 2020-01-11 04:35:07
问题 This is supposed to be a string class with a bunch of operators and functions, including two friend functions. And those two cause some trouble for me, because the compiler says that they can not access the private members. Here is my string.h: #include <iostream> #ifndef STR_H #define STR_H namespace MyStr { class Str { private: unsigned int length; char *data; public: Str(); Str(const Str&); Str(const char*); Str(char c, unsigned int db); ~Str(); char* cStr() const; unsigned int getLength()

C++ friends in template classes, separation of interface and implementation [duplicate]

旧时模样 提交于 2020-01-07 03:08:35
问题 This question already has answers here : Why can templates only be implemented in the header file? (16 answers) Closed 4 years ago . The following code works fine: Class.h: #ifndef ClassLoaded #define ClassLoaded #include <iostream> template <class T> class Class{ public: template <class T> friend std::ostream& operator<<(std::ostream& Stream, const Class<T>& Op); }; #endif Class.cpp: #include "Class.h" template class Class<int>; template std::ostream& operator<<(std::ostream& Stream, const

Unable get all fields of friend list in facebook sdk sample and In Friend Picker Sample getting only id,name in android

做~自己de王妃 提交于 2020-01-05 03:10:16
问题 I am developing facebok sample demo for get all friend list of login user. I am running Friend Picker Sample successfully,But getstuck to extract all the details of friends like email,first_name,last_name etc.I am getting only id,name. If anyone have idea please reply. Here is mycode:- public void getFriends(Properties properties, final OnFriendsRequestListener onFriendsRequestListener) { // if we are logged in if (isLogin()) { // move these params to method call parameters Session session =

Is Game Center Multiplayer Friends broken in IOS 9?

半腔热情 提交于 2020-01-03 13:10:10
问题 I created a game that uses real-time multiplayer programmatically. It was originally targeted to towards IOS 8 devices. Recently after migration to IOS 9, Game Center has caused a lot of problems. The main issue I cannot resolve is Inviting a friend in multiplayer (for testing). From IOS 8 to IOS 8. Auto match works and Friend invitations work But from IOS 9 to IOS 9. Auto match works and Friend invitations do not work anymore. If any of you have managed to make Game Center invitations work

C++: Correct syntax for friending a template type member of template parameter?

被刻印的时光 ゝ 提交于 2020-01-03 08:27:10
问题 I have a class that takes a template type parameter (tTRAIT). I want to friend a template type member alias of tTRAIT, but I can't figure out the syntax. (Is this even possible?). template <bool bBOOL> struct SFoo {}; struct STrait { template <bool bBOOL> using TFoo = SFoo<bBOOL>; }; template <typename tTRAIT> struct SBar { template <bool bBOOL> friend typename tTRAIT::template TFoo<bBOOL>; }; SBar<STrait> bar; Clang's error (on the friend line) is: error: friend type templates must use an