virtual

C++ vtable resolving with virtual inheritance

故事扮演 提交于 2019-12-10 10:37:07
问题 I was curious about C++ and virtual inheritance - in particular, the way that vtable conflicts are resolved between bass and child classes. I won't pretend to understand the specifics on how they work, but what I've gleamed so far is that their is a small delay caused by using virtual functions due to that resolution. My question then is if the base class is blank - ie, its virtual functions are defined as: virtual void doStuff() = 0; Does this mean that the resolution is not necessary,

Covariant virtual functions return type problem

情到浓时终转凉″ 提交于 2019-12-10 10:23:12
问题 I have following code: #include <iostream> using namespace std; class Child1 { int i; }; class Child2 : public Child1 { int j; }; class Base1 { public: virtual Child1& getChildren() { cout << "Children1" << endl; return children; } private: Child1 children; }; class Base2 : public Base1 { public: virtual Child2& getChildren() { cout << "Children2" << endl; return children; } private: Child2 children; }; This code compiles fine but when I change the return type of getChildren() from reference

C++ - “Member function not declared” in derived class

一笑奈何 提交于 2019-12-10 04:17:01
问题 I have a problem in MSVC++ 2008 where VS2008 is throwing this compile error: error C2509: 'render' : member function not declared in 'PlayerSpriteKasua' Now, what's confusing me is that render() is defined, but in an inherited class. The class definition works like this: SpriteBase -Inherited By-> PlayerSpriteBase -Inherited By-> PlayerSpriteKasua So, a pared-down version of SpriteBase.h is the following: class SpriteBase { public: //Variables=============================================

templates may not be ‘virtual’

跟風遠走 提交于 2019-12-10 01:00:52
问题 Given the code below, the compiler is showing a message pointing that error: templates may not be ‘virtual’ . Does anyone have a suggestion on how to solve the bug? template < class FOO_TYPE> class CFoo{ public: ... template < class BAR_TYPE > virtual void doSomething( const CBar<BAR_TYPE> &); // here's the error ... virtual ~CFoo(); protected: MyClass < FOO_TYPE > * m_pClass; }; template < class FOO_TYPE > template < class BAR_TYPE > void CFoo<FOO_TYPE>::doSomething( const CBar<BAR_TYPE> &

继承中构造函数和析构函数的调用顺序

痴心易碎 提交于 2019-12-09 20:40:44
由架构中基类的设计想到的...... 现在,有三个类,类的定义如下 #include <iostream> using namespace std; class CA { public: CA(){ cout << "CA constructor" << endl; } ~CA(){ cout << "CA destructor" << endl; } }; class CB:public CA { public: CB(){ cout << "CB constructor" << endl; } ~CB(){ cout << "CB destructor" << endl; } }; class CC:public CB { public: CC(){ cout << "CC constructor" << endl; } ~CC(){ cout << "CC destructor" << endl; } }; int main(int argc, char* argv[]) { CC c; return 0; } CA 是爷爷, CB 是爸爸, CC 是儿子。 那么任何一本 C++ 的书都会讲,构造函数的调用顺序是 CA CB CC ,析构函数的调用顺序是 CC,CB,CA ,什么???你的书没讲,靠,扔了吧。 于是, 这个程序运行结果是 CA constructor CB

Delphi - convert physical path (device File handle) to virtual path

余生长醉 提交于 2019-12-09 18:58:40
问题 How can I convert a path like \Device\HarddiskVolume3\Windows into its corresponding virtual path? (like c:\Windows in this case) 回答1: Personally I prefer the native way: function GetHDDDevicesWithDOSPath:TStringlist; var i: integer; root: string; device: string; buffer: string; begin setlength(buffer, 1000); result:=TStringlist.create; for i := Ord('c') to Ord('z') do begin root := Char(i) + ':'; if (QueryDosDevice(PChar(root), pchar(buffer), 1000) <> 0) then begin device := pchar(buffer);

Strange behaviour when calling virtual functions

两盒软妹~` 提交于 2019-12-09 18:33:39
问题 I don't understand what is wrong with this code. It looks like an incredible trap ! This code : class Foo { public: virtual double foo(double x) const = 0; double foo(int x) const { return (double)(x + x); } }; class Bar : public Foo { public: virtual double foo(double x) const { return x * x; } }; int main() { Bar* b = new Bar; Foo* f = b; std::cout << b->foo(3) << " " << f->foo(3) << std::endl; std::cout << b->foo(5.0) << " " << f->foo(5.0) << std::endl; return 0; } prints the following

何时使用虚拟析构函数?

北战南征 提交于 2019-12-09 11:21:10
我对大多数面向对象理论有扎实的了解,但令我困惑的一件事是虚拟析构函数。 我以为无论链中的每个对象是什么,析构函数总是被调用。 您打算何时将它们虚拟化?为什么? #1楼 我喜欢考虑接口和接口的实现。 在C ++中,接口是纯虚拟类。 析构函数是接口的一部分,有望实现。 因此,析构函数应该是纯虚拟的。 构造函数呢? 构造函数实际上不是接口的一部分,因为对象总是显式实例化的。 #2楼 虚拟构造函数是不可能的,但虚拟析构函数是可能的。 让我们尝试一下... #include <iostream> using namespace std; class Base { public: Base(){ cout << "Base Constructor Called\n"; } ~Base(){ cout << "Base Destructor called\n"; } }; class Derived1: public Base { public: Derived1(){ cout << "Derived constructor called\n"; } ~Derived1(){ cout << "Derived destructor called\n"; } }; int main() { Base *b = new Derived1(); delete b; } 上面的代码输出以下内容:

What does it mean when “virtual” is in “class Foo : public virtual Bar” as opposed to “virtual void frob()”?

最后都变了- 提交于 2019-12-09 10:27:05
问题 What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"? For a given method there are 8 cases stemming from the presence or absence of virtual in the following three locations. A superclass's functions. The inheritance chain for this class. This classes functions. I think I understand how numbers 1 and 3 interact but number 2 seems redundant. Is it? What am I not understanding? 回答1: That's virtual inheritance, you do it when you know you'll

cannot open manage.py after installing django

狂风中的少年 提交于 2019-12-09 06:03:58
问题 I have a problem in setting up django. My situation: I have Anaconda Python 2.7 in my Windows 8 computer. On the Anaconda command prompt window, I type: pip install django . This is successful. Then I create a folder named "newproject". On the command prompt I went to the folder "newproject". Then django-admin.py startproject newproject . This is successful. Then I run python manage.py runserver . It tells me "...can't open file 'manage.py': [Errno 2] No such file or directory" I checked out