virtual

Mongoose complex (async) virtuals

喜你入骨 提交于 2019-11-26 17:07:32
问题 I have two mongoose schemas as follow: var playerSchema = new mongoose.Schema({ name: String, team_id: mongoose.Schema.Types.ObjectId }); Players = mongoose.model('Players', playerSchema); var teamSchema = new mongoose.Schema({ name: String }); Teams = mongoose.model('Teams', teamSchema); When I query Teams I would to get also the virtual generated squad : Teams.find({}, function(err, teams) { JSON.stringify(teams); /* => [{ name: 'team-1', squad: [{ name: 'player-1' } , ...] }, ...] */ });

Can you write virtual functions / methods in Java?

橙三吉。 提交于 2019-11-26 17:04:00
Is it possible to write virtual methods in Java, as one would do in C++? Or, is there a proper Java approach which you can implement that produces similar behavior? Could I please have some examples? Klaus Byskov Pedersen From wikipedia In Java , all non-static methods are by default " virtual functions. " Only methods marked with the keyword final , which cannot be overridden, along with private methods , which are not inherited, are non-virtual . Eric Leschinski Can you write virtual functions in Java? Yes. In fact, all instance methods in Java are virtual by default. Only certain methods

C++ virtual override functions with same name

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 16:58:47
问题 I have something like that (simplified) class A { public: virtual void Function () = 0; }; class B { public: virtual void Function () = 0; }; class Impl : public A , public B { public: ???? }; How can I implement the Function () for A and the Function() for B ? Visual C++ lets you only define the specific function inline (i.e. not in the cpp file), but I suppose it's an extension. GCC complains about this. Is there a standard C++ way to tell the compiler which function I want to override?

C++ Virtual template method

浪子不回头ぞ 提交于 2019-11-26 16:16:37
I have an abstract class (I know that it will not compile this way, but it's for comprehension of what I want to do) : class AbstractComputation { public: template <class T> virtual void setData(std::string id, T data); template <class T> virtual T getData(std::string id); }; class Computation : public AbstractComputation { public: template <class T> void setData(std::string id, T data); template <class T> T getData(std::string id, T data); }; So when I call setData<double>("foodouble", data) I want the double identified by foodouble (internal mechanism which is not the main concern here) to

Making operator<< virtual?

时光怂恿深爱的人放手 提交于 2019-11-26 16:08:02
I need to use a virtual << operator. However, when I try to write: virtual friend ostream & operator<<(ostream& os,const Advertising& add); I get the compiler error Error 1 error C2575: 'operator <<' : only member functions and bases can be virtual How can I turn this operator virtual? The problem with this setup is that the operator<< you defined above is a free function, which can't be virtual (it has no receiver object). In order to make the function virtual, it must be defined as a member of some class, which is problematic here because if you define operator<< as a member of a class then

Why are private virtual methods illegal in C#?

眉间皱痕 提交于 2019-11-26 15:34:56
问题 Coming from a C++ background, this came as a surprise to me. In C++ it's good practice to make virtual functions private. From http://www.gotw.ca/publications/mill18.htm: "Guideline #2: Prefer to make virtual functions private." I also quote Eric Lippert's blog, from Knights-knaves-protected-and-internal: Private virtual methods are illegal in C#, which irks me to no end. I would totally use that feature if we had it. I understand that in C#, you wouldn't be able to override a private virtual

CRTP to avoid dynamic polymorphism

China☆狼群 提交于 2019-11-26 14:54:01
How can I use CRTP in C++ to avoid the overhead of virtual member functions? There are two ways. The first one is by specifying the interface statically for the structure of types: template <class Derived> struct base { void foo() { static_cast<Derived *>(this)->foo(); }; }; struct my_type : base<my_type> { void foo(); // required to compile. }; struct your_type : base<your_type> { void foo(); // required to compile. }; The second one is by avoiding the use of the reference-to-base or pointer-to-base idiom and do the wiring at compile-time. Using the above definition, you can have template

Alternative virtual mechanism implementations?

早过忘川 提交于 2019-11-26 14:20:44
C++ supports dynamic binding through virtual mechanism. But as I understand the virtual mechanism is an implementation detail of the compiler and the standard just specifies the behaviors of what should happen under specific scenarios. Most compilers implement the virtual mechanism through the virtual table and virtual pointer. And yes I am aware of how this works, So my question is not about implementation detail of virtual pointers and table. My questions are: Are there any compilers which implement Virtual Mechanism in any other way other than the virtual pointer and virtual table mechanism

Print address of virtual member function

天涯浪子 提交于 2019-11-26 14:16:05
问题 I am trying to print the address of a virtual member function. If I know which class implements the function I can write: print("address: %p", &A::func); But I want to do something like this: A *b = new B(); printf("address: %p", &b->func); printf("address: %p", &b->A::func); However this does not compile. Is it possible to do something like this, perhaps looking up the address in the vtable at runtime? 回答1: Currently there is no standard way of doing this in C++ although the information must

Why use &#39;virtual&#39; for class properties in Entity Framework model definitions?

☆樱花仙子☆ 提交于 2019-11-26 12:40:00
In the following blog: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx The blog contains the following code sample: public class Dinner { public int DinnerID { get; set; } public string Title { get; set; } public DateTime EventDate { get; set; } public string Address { get; set; } public string HostedBy { get; set; } public virtual ICollection<RSVP> RSVPs { get; set; } } public class RSVP { public int RsvpID { get; set; } public int DinnerID { get; set; } public string AttendeeEmail { get; set; } public virtual Dinner Dinner { get; set; } }