In C ++, when can a virtual function use static binding? If it is accessed through a pointer that is accessed directly or never?
When a virtual method is invoked through a pointer or reference, dynamic binding is used. Compile time binding is used at any other time. Example:
class C; void Foo(C* a, C& b, C c) { a->foo(); // dynamic b.foo(); // dynamic c.foo(); // static (compile-time) }
If you want to call the base class version of a function, you can do this by explicitly calling the base class:
class Base { public: virtual ~Base() {} virtual void DoIt() { printf("In Base::DoIt()\n"); } }; class Derived : public Base { public: virtual void DoIt() { printf("In Derived::DoIt()\n"); } }; Base *basePtr = new Derived; basePtr->DoIt(); // Calls Derived::DoIt() through virtual function call basePtr->Base::DoIt(); // Explicitly calls Base::DoIt() using normal function call delete basePtr;
, . , : , , , . , , ( , , , , , , undefined ). , , , , . !
Source: https://habr.com/ru/post/1699188/More articles:Passing AD authentication credentials through IE browser in C # Windows Form - c #How to find all occurrences of a sequence of characters when a certain string is preceded? - ruby | fooobar.comПреобразование SQL в HQL - hibernateDoxygen language and Assembly - assemblyКак я могу программно установить свойство сайта Search Center на сайте SharePoint? - propertiesGetting rid of the gcc shift with a negative warning - c ++C ++ project structure in Visual Studio 2008 - c ++Sql Server Management Studio 2008 does not allow the use of table tables - sql-serverHow to revoke Windows Administrator user permission from DB2? - db2Google AppEngine POST request file name - postAll Articles