virtual

Can you override private virtual methods?

﹥>﹥吖頭↗ 提交于 2019-12-21 04:12:17
问题 I think you can and my colleage thinks you cannot! 回答1: You can't even declare private virtual methods. The only time it would make any sense at all would be if you had: public class Outer { private virtual void Foo() {} public class Nested : Outer { private override void Foo() {} } } ... that's the only scenario in which a type has access to its parent's private members. However, this is still prohibited: Test.cs(7,31): error CS0621: 'Outer.Nested.Foo()': virtual or abstract members cannot

why is my c program suddenly using 30g of virtual memory?

不打扰是莪最后的温柔 提交于 2019-12-21 03:50:34
问题 In top, I noticed that my c program (using CUDA 3.2) has a virtual size of 28g or more (looking at VIRT), on every run right from the beginning. This doesn't make ANY sense to me. The resident memory makes sense and is only around 2g on my largest data set. I know at some point in the past the virtual size was not so large, but I'm not sure when the change occurred. Why would my process use 28g of virtual memory (or why would top's VIRT be so large)? I understand that VIRT includes the

How to hack the virtual table?

此生再无相见时 提交于 2019-12-20 09:19:01
问题 I would like to know how to change the address of Test which is in the virtual table with that of HackedVTable . void HackedVtable() { cout << "Hacked V-Table" << endl; } class Base { public: virtual Test() { cout <<"base"; } virtual Test1() { cout << "Test 1"; } void *prt; Base(){} }; class Derived : public Base { public: Test() { cout <<"derived"; } }; int main() { Base b1; b1.Test(); // how to change this so that `HackedVtable` should be called instead of `Test`? return 0; } Answer will be

How to Create a Virtual Windows Drive

筅森魡賤 提交于 2019-12-20 08:41:16
问题 I'm trying to create a Windows Virtual Drive ( like c:\ ) to map a remote storage. The main purpose is to do it in a clear way to the user. Therefore the user wouldn't know that he is writing/reading from another site. I was searching for available products, and i find that FUSE is not an option in Windows and WebDAV maps directly the drive, and i would like to build a middle layer between windows and remote storage to implement some kind of services. Another alternatives exists, such as

Comparison : interface methods vs virtual methods vs abstract methods

情到浓时终转凉″ 提交于 2019-12-20 08:34:01
问题 What are the advantages and disadvantages of each of these? interface methods virtual methods abstract methods When one should choose what? What are the points one should keep in mind when making this decision? 回答1: Virtual and abstract are almost the same. A virtual method has an implementation in the base class that can optionally be overridden, while an abstract method hasn't and must be overridden in a child class. Otherwise they are the same. Choosing between them depends on the

Python calling subprocess that requires no virtual environment

醉酒当歌 提交于 2019-12-20 03:48:09
问题 I have a Python 3.6 script that calls out to a third-party tool using subprocess. main_script.py: #!/usr/bin/env python import subprocess result = subprocess.run(['third-party-tool', '-arg1'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) The problem is, main_script.py must be run from within a virtual environment, and third-party-tool must be run from no virtual environment whatsoever. I don't know much about third-party-tool , except that it is on my path. Calling it while I

Overriding an abstract method with a virtual one

冷暖自知 提交于 2019-12-19 18:20:13
问题 I'm trying to override an abstract method in an abstract class with a virtual method in a child class. I (assumed until now?) understand the difference between abstract and virtual methods. Obviously I'm not able to do it but my question is... why? Based on the accepted answer here and the following scenario, I just don't see the problem: public abstract class TopLevelParent { protected abstract void TheAbstractMethod(); } public class FirstLevelChild1 : TopLevelParent { protected override

Virtual Functions and Performance C++

只愿长相守 提交于 2019-12-19 17:41:59
问题 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:

Is it recommended to explicitly make overriding functions virtual?

冷暖自知 提交于 2019-12-19 17:30:36
问题 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

C++ : implications of making a method virtual

家住魔仙堡 提交于 2019-12-19 10:22:33
问题 Should be a newbie question... I have existing code in an existing class, A, that I want to extend in order to override an existing method, A::f(). So now I want to create class B to override f(), since I don't want to just change A::f() because other code depends on it. To do this, I need to change A::f() to a virtual method, I believe. My question is besides allowing a method to be dynamically invoked (to use B's implementation and not A's) are there any other implications to making a