friend

Symfony Doctrine entity friend hasFriend followers

偶尔善良 提交于 2019-12-04 17:25:42
I need to set follower, following (myFriends) hasFriend logic to my project. column "odobera" means "following" to example nick(id user) odobera (following to this user). User (25) is following user(37). Requests table: User entity: /** * @ORM\OneToMany(targetEntity="TB\RequestsBundle\Entity\Requests", mappedBy="odobera") */ protected $followers; /** * @ORM\OneToMany(targetEntity="TB\RequestsBundle\Entity\Requests", mappedBy="nick") */ protected $myFriends; public function __construct() { parent::__construct(); $this->followers = new \Doctrine\Common\Collections\ArrayCollection(); $this-

Why does the Standard prohibit friend declarations of partial specializations?

断了今生、忘了曾经 提交于 2019-12-04 16:24:56
问题 The C++ standard prohibits friend declarations of partial specializations. (§14.5.3/8): Friend declarations shall not declare partial specializations. [Example: template<class T> class A { }; class X { template <class T> friend class A<T*>; //error }; --end example] Other questions, e.g. this one, have received answers that invoke this prohibition, but I would like to know the rationale. I don't see it and can't find it with my favourite search engine. I can find however that it goes right

private inheritance, friends, and exception-handling

99封情书 提交于 2019-12-04 11:20:58
When class A privately inherits from class B it means that B is a private base class subobject of A. But not for friends, for friends it is a public sububject. And when there are multiple catch handlers the first one that matches (that is, if the exception type can be implicitly converted to the handler's parameter type) is called. So will anyone explain to me why the following code does not work as I expect? Is this behavior intended by the standard or is this a MSVC bug? class A { }; class B:A //private inheritance { friend void g(); }; void f() { B b; //A* pa = &b; // error, conversion

Specify a class member function as a friend of another class?

蓝咒 提交于 2019-12-04 10:11:40
问题 According to the C++ Primer book, the author mentioned that We can specify a class member function as a friend of another class, instead of the entire class (page 634). Then, I tested this code: class A { public: friend void B::fB(A& a); void fA(){} }; class B { public: void fB(A& a){}; void fB2(A& a){}; }; I just wanted the fB() to be friend of class A, not the entire class B. But the about code produced an error: 'B' : is not a class or namespace name . (I am using Visual C++ 2005) 回答1: Try

Virtual friend functions for a base class?

无人久伴 提交于 2019-12-04 09:21:30
问题 I'm in the proccess of learning the language and this is a noob doubt. Is it possible to use a virtual friend function? I don't know if it's possible, I didn't even test it but it could be useful in some situations. For example, for the overloaded operator<<(). DerivedClass dc; BaseClass &rbc = dc; cout << rbc; My guess is it's possible, but I'm not sure since a friend function is not implemented in the class design, and theoretically is not part of it (though in this example, conceptually it

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

不打扰是莪最后的温柔 提交于 2019-12-04 08:11:01
问题 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 boost::make_shared. I decided to my boost::make_shared a friend of my class but I'm puzzled about the syntax. I tried template< class T, class A1, class A2 >

Compiler error in declaring template friend class within a template class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 00:57:10
I have been trying to implement my own linked list class for didactic purposes. I specified the "List" class as friend inside the Iterator declaration, but it doesn't seem to compile. These are the interfaces of the 3 classes I've used: Node.h: #define null (Node<T> *) 0 template <class T> class Node { public: T content; Node<T>* next; Node<T>* prev; Node (const T& _content) : content(_content), next(null), prev(null) {} }; Iterator.h: #include "Node.h" template <class T> class Iterator { private: Node<T>* current; Iterator (Node<T> *); public: bool isDone () const; bool hasNext () const; bool

Can a friend class object access base class private members on a derived class object?

守給你的承諾、 提交于 2019-12-04 00:31:34
I'm surprised that the code below compiles. It seems that a class befriended to the (publicly inherited) base class can access a member of the base class provided an instance of the derived class. If the inheritance is changed to private then compilation fails. In short, how is d.b_var valid within F::func(D& d) ? #include <iostream> #include <string> using namespace std; class B{ int b_var; friend class F; }; class D: public B{ int d_var; }; class F{ public: void func(D &d){ d.b_var = 5; } }; int main() { cout<<"fine"; } sameerkn Object of class D is composed of 2 separate parts : part

PHP: friend classes and ungreedy caller function/class

徘徊边缘 提交于 2019-12-03 21:49:33
Is there any way to get the caller function with something else than debug_backtrace()? I'm looking for a less greedy way to simulate scopes like friend or internal . Let's say I have a class A and a class B. Until now, I've been using debug_backtrace() , which is too greedy (IMHO). I thought of something like this: <?php class A { public function __construct(B $callerObj) {} } class B { public function someMethod() { $obj = new A($this); } } ?> It might be OK if you want to limit it to one specific class, but let's say I have 300 classes, and I want to limit it to 25 of them? One way could be

Is friendship inherited in C++?

那年仲夏 提交于 2019-12-03 17:11:42
问题 Suppose I have a Base class: class Base { friend SomeOtherClass; }; And there is another (different) class that inherits from Base : class AnotherClass : public Base {} Is friendship inherited as well? 回答1: In principle, a derived class inherits every member of a base class except: * its constructor and its destructor * its operator=() members * its friends So, no. Friends are not inherited. 回答2: No it isn't. Edit: To quote from the C++ Standard, section 11.4/8 Friendship is neither inherited