pure-virtual

Is there any point in using `override` when overriding a pure virtual function?

孤街醉人 提交于 2020-06-09 15:23:06
问题 For example: class Base { virtual void my_function() = 0; }; class Derived : Base { void my_function() override; }; From what I read, the override keyword is used to make sure that we have the correct signature in the function that we are overriding, and it seems to be its only use. However, in the case of a pure virtual function, the compiler would throw an error if we used an incorrect signature in the Derived class (or Base class, depending on how one see things). So, is there any point in

Unimplemented Pure Virtual Method?

吃可爱长大的小学妹 提交于 2020-05-23 10:37:07
问题 Here is the problem: I keep getting the unimplemented pure virtual method error when trying to compile. I have implemented all of the pure virtual methods in the abstract base class. Any ideas? here is the abstract base class: class record{ public: virtual int getID()=0; virtual record *clone(); }; and the implementation: class sdata: public record{ public: sdata(std::string s = ""){data=s; ID=atoi(data.substr(0,8).c_str());} virtual int getID(){return ID;} private: std::string data; int ID;

Unimplemented Pure Virtual Method?

做~自己de王妃 提交于 2020-05-23 10:37:04
问题 Here is the problem: I keep getting the unimplemented pure virtual method error when trying to compile. I have implemented all of the pure virtual methods in the abstract base class. Any ideas? here is the abstract base class: class record{ public: virtual int getID()=0; virtual record *clone(); }; and the implementation: class sdata: public record{ public: sdata(std::string s = ""){data=s; ID=atoi(data.substr(0,8).c_str());} virtual int getID(){return ID;} private: std::string data; int ID;

Can I override a virtual function with a pure virtual one?

感情迁移 提交于 2020-03-13 04:42:33
问题 I have three classes: B , D and G . D is a B and G is a D . Both B and D are abstract. B is from a third party. B has a non-pure, virtual method that G needs to implement (to be a D ). Can I and is it good practice to redefine/override a virtual function to be pure virtual? Example: class B // from a third party { public: virtual void foo(); }; class D : public B { public: void foo() override = 0; // allowed by gcc 4.8.2 virtual void bar() = 0; }; class G : public D { public: // forgot to

Are there pure virtual functions in PHP like with C++

不羁岁月 提交于 2020-02-20 07:00:11
问题 I would have thought lots of people would have wondered whether this is possible but I can't find any duplicate questions... do correct me. I just want to know whether PHP offers pure virtual functions. I want the following class Parent { // no implementation given public function foo() { // nothing } } class Child extends Parent { public function foo() { // implementation of foo goes here } } Thanks very much. 回答1: You can create abstract functions, but you need to declare the parent class

Are there pure virtual functions in PHP like with C++

牧云@^-^@ 提交于 2020-02-20 06:58:45
问题 I would have thought lots of people would have wondered whether this is possible but I can't find any duplicate questions... do correct me. I just want to know whether PHP offers pure virtual functions. I want the following class Parent { // no implementation given public function foo() { // nothing } } class Child extends Parent { public function foo() { // implementation of foo goes here } } Thanks very much. 回答1: You can create abstract functions, but you need to declare the parent class

How to handle destructors in DLL exported interfaces

≯℡__Kan透↙ 提交于 2020-01-23 12:29:09
问题 I'm trying to export a class from a DLL. I read this article on doing so: http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL The "mature" approach suggest, that an abstract class is used, so I have: // Header class IFoo{ public: virtual int getBar() = 0; } class Foo: public IFoo {...} DLLEXPORT IFoo* Create(); DLLEXPRT void Free(IFoo* inst); //DLL cpp IFoo* Create(){ return new Foo; } void Free(IFoo* inst){ delete inst; } What puzzles me: If I don't have a virtual

Pointer derived from pure virtual class(A) can't access overload method from the pure class (B)

你。 提交于 2020-01-22 23:08:47
问题 Consider I have two pure virtual classes, one deriving from the another and a concrete class deriving from the last mentioned: #include <iostream> #include <string> class Abstract1 { public: virtual ~Abstract1() { }; virtual void method(int a) = 0; protected: Abstract1() = default; }; class Abstract2: public Abstract1 { public: virtual ~Abstract2() { }; virtual void method(char c, std::string s) = 0; protected: Abstract2() = default; }; class Concrete : public Abstract2 { public: void method

Pointer derived from pure virtual class(A) can't access overload method from the pure class (B)

梦想与她 提交于 2020-01-22 23:05:11
问题 Consider I have two pure virtual classes, one deriving from the another and a concrete class deriving from the last mentioned: #include <iostream> #include <string> class Abstract1 { public: virtual ~Abstract1() { }; virtual void method(int a) = 0; protected: Abstract1() = default; }; class Abstract2: public Abstract1 { public: virtual ~Abstract2() { }; virtual void method(char c, std::string s) = 0; protected: Abstract2() = default; }; class Concrete : public Abstract2 { public: void method

A virtual member function is used if it is not pure?

被刻印的时光 ゝ 提交于 2020-01-12 07:42:07
问题 C++03 3.2.2 ...An object or non-overloaded function is used if its name appears in a potentially-evaluated expression. A virtual member function is used if it is not pure... And then later in 3.2.3 we have: Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is