virtual

Virtual Functions and Performance C++

元气小坏坏 提交于 2019-12-01 16:54:19
Before you cringe at the duplicate title, the other question wasn't suited to what I ask here (IMO). So. I am really wanting to use virtual functions in my application to make things a hundred times easier (isn't that what OOP is all about ;)). But I read somewhere they came at a performance cost, seeing nothing but the same old contrived hype of premature optimization, I decided to give it a quick whirl in a small benchmark test using: CProfiler.cpp #include "CProfiler.h" CProfiler::CProfiler(void (*func)(void), unsigned int iterations) { gettimeofday(&a, 0); for (;iterations > 0; iterations

Is it recommended to explicitly make overriding functions virtual?

谁说胖子不能爱 提交于 2019-12-01 16:46:00
In times before C++11 when a virtual function was overriden in a derived class, it was recommended to add the virtual keyword also to the derived class function to make the intention clear. Nowadays such a function is marked "override" which kind of includes the notion that there must be a virtual base function. Therefore I am now preferring to omit the virtual: class Derived: public Base { public: void Overriden() override; // Instead of: virtual void Overriden() override; }; However this leads to an IntelliSense error in MSVC 2012: the 'override' modifier requires a virtual function

Photon Server 实现注册与登录(一) --- Hibernate整合到项目中

人走茶凉 提交于 2019-12-01 15:24:02
本系列实现目的:基于Photon Server实现注册于登录 一、拷贝Nbibernate项目的文件到MyGamerServer项目中。 二、数据库新建表,结构如下 三、修改文件名和配置   (1)、将拷贝的文件修改一下名字(不是必须)。修改为与User相关的。注意:修改文件下的包名也得修改,由 Nbibernate.l 修改为MyGameServer.  (2)、Model文件调整。目录 Model/下的User.cs文件字段修改为与数据库users表字段相同 namespace MyGameServer.Model { public class User { //字段跟数据库表列一样 public virtual int Id { get; set; } public virtual string UserName { get; set; } public virtual string Password { get; set; } public virtual string RegisterDate { get; set; } } } (3)、映射文件 Mappings/ 目录下的User.hbm.xml 修改 <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate

Polymorphism and casting

不羁岁月 提交于 2019-12-01 15:16:31
I want to understand polymorphism in c# so by trying out several constructs I came up with the following case: class Shape { public virtual void Draw() { Console.WriteLine("Shape.Draw()"); } } class Circle : Shape { public override void Draw() { Console.WriteLine("Circle.Draw()"); } } I understand that in order to send the Draw() message to several related objects, so they can act according to its own implementation I must change the instance to which (in this case) shape is 'pointing' to: Shape shape = new Circle(); shape.Draw(); //OK; This prints: Circle.Draw() But why, when I do this:

Actionscript3 Main class is the root, but does not allow the Animate Virtual Camera

和自甴很熟 提交于 2019-12-01 14:48:29
I've recently started learning Animate CC with Actionscript 3. I'm trying to use Animate's "Virtual Camera" feature, giving me a camera that can pan, rotate, and zoom the game. It's easy to implement a Camera when the root has no subclass. For example, you can put a block on screen, and add a camera effect within the timeline itself, and play your movie it. Easy. But when I give the fla a class ("Main") and give that class an external AS3 file, I get an error: Specific image showcasing what I mean about giving FLA a class The code below is "Main.as" package { import flash.display.MovieClip;

Entity Framework应用:Loading Entities

限于喜欢 提交于 2019-12-01 14:14:21
Entity Framework允许控制对象之间的关系,在使用EF的过程中,很多时候我们会进行查询的操作,当我们进行查询的时候,哪些数据会被加载到内存中呢?所有的数据都需要吗?在一些场合可能有意义,例如:当查询的实体仅仅拥有一个相关的子实体时可以加载所有的数据到内存中。但是,在多数情况下,你可能并不需要加载全部的数据, 而是只要加载一部分的数据即可。 默认情况下,EF仅仅加载查询中涉及到的实体,但是它支持两种特性来帮助你控制加载: 1、贪婪加载 2、延迟加载 下面以客户类型、客户和客户邮件三个实体之间的关系来讲解两种加载方式。 从上图可以看出三个实体类之间的关系: 客户类型和客户是一对多的关系:一个客户类型可以有多个客户。 客户和客户邮件是一对一的关系:一个客户只有一个邮箱地址。(假设只有一个邮箱地址) 一、延迟加载(Lazy Loading) 延迟加载:即在需要或者使用的时候才会加载数据。默认情况下,EF使用延迟加载的方式来加载数据。延迟加载是这样一种过程:直到LINQ查询的结果被枚举时,该查询涉及到的相关实体才会从数据库加载。如果加载的实体包含了其他实体的导航属性,那么直到用户访问该导航属性时,这些相关的实体才会被加载。 使用延迟加载必须满足两个条件: 1、实体类是由Public修饰符修饰的,不能是封闭类。 2、导航属性标记为Virtual。 1、定义实体类

Actionscript3 Main class is the root, but does not allow the Animate Virtual Camera

我的梦境 提交于 2019-12-01 13:30:47
问题 I've recently started learning Animate CC with Actionscript 3. I'm trying to use Animate's "Virtual Camera" feature, giving me a camera that can pan, rotate, and zoom the game. It's easy to implement a Camera when the root has no subclass. For example, you can put a block on screen, and add a camera effect within the timeline itself, and play your movie it. Easy. But when I give the fla a class ("Main") and give that class an external AS3 file, I get an error: Specific image showcasing what I

Call derived class non virtual member functions from base class pointer

我与影子孤独终老i 提交于 2019-12-01 12:10:39
We know that, derived class members functions can be accessed through a base class pointer in C++ , provided that these member functions have to be virtual. Is there a means to access derived class member functions which are NOT virtual or pure virtual from base class pointer. i.e. I want to call derived class member functions which are present only in derived class & not in base class through base class pointer. How would I achieve this? For example, if I design a factory design pattern, class Vehicle { public: virtual void printVehicle() = 0; static Vehicle* Create(VehicleType type); };

Call derived class non virtual member functions from base class pointer

蹲街弑〆低调 提交于 2019-12-01 12:02:10
问题 We know that, derived class members functions can be accessed through a base class pointer in C++ , provided that these member functions have to be virtual. Is there a means to access derived class member functions which are NOT virtual or pure virtual from base class pointer. i.e. I want to call derived class member functions which are present only in derived class & not in base class through base class pointer. How would I achieve this? For example, if I design a factory design pattern,

How to write a driver for virtual printer

我与影子孤独终老i 提交于 2019-12-01 11:13:57
I want to write a driver for virtual printer (in C++ or Java) (As explained in How to create a virtual printer in Windows? ) I would redirect the file to a file server (again as explained in http://www.colorpilot.com/VirtualPrinterForCSharp2.html . What are the fundamental building blocks of a printer driver ? I have read about spooler and print monitor but I am not sure that these are all that I have to know! Any guide or suggestion appreciated in advance! Regards Most print redirection requirements are fulfilled using a Port Monitor. You dont need to do a printer driver because if you do