virtual-functions

Implement abstract methods from inherited class

梦想的初衷 提交于 2019-12-06 14:32:41
I am trying to do something I haven't really done before. I basically have 3 classes. Class A is an abstract class with pure virtual methods, Class B is a class on it's own that contains methods with the same name as the virtual methods in Class A. I'm trying to tie everything together in Class C. I'd like to inherit class B and A in C (multiple inheritance), and use the methods from Class B to implement those in class A. This way I create a modular approach. The example below is a very simplified version of my code. class A { virtual int methodA() = 0; virtual int methodB() = 0; virtual int

pure virtual method called error

橙三吉。 提交于 2019-12-06 13:41:12
I have the following definitions: class PartitioningMethod { public: virtual void addConstraints(ConstraintManager& cm) = 0; virtual bool hasMoreConstraints() = 0; virtual void setQuery(const Query& q) = 0; virtual ~PartitioningMethod(){ } }; class Random : public PartitioningMethod { private: vector< ref<Expr> > constraints; vector< ref<Expr> >::iterator it; vector< ref<Expr> >::iterator end; int numConstraints; RNG theRNG; public: void setQuery(const Query& q) { constraints.clear(); //Set random number //srand ( unsigned ( time (NULL) ) * theRNG.getInt32() ); srand ( theRNG.getInt32() ); /

Debug Assertion Failed! Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

一曲冷凌霜 提交于 2019-12-06 13:18:21
I know this problem is assessed many times on these forums, but they really are unique to their specific cases most times. This is a project for a class (on C++ no less), and the point of the project was to remake the classic board game Reversi. I have toiled through code for hours and finally made a program that will work, or so I thought! The big problem I am having seems to come from my deconstructor as it's giving me this error many of us have seen. My code is posted below and from my own debugging code (using helpful cout messages) I have determined that the program manages to run to the

Using virtual functions in CUDA kernels

故事扮演 提交于 2019-12-06 07:03:12
问题 So I want to allocate an object with virtual functions on the device, then call a kernel and execute some of those virtual functions. I have tried two ways to do this but neither work: 1) Allocate and copy the object from the host using cudaMalloc and cudaMemcpy. This copies over the virtual function table that contains host memory pointers which obviously crash the kernel when executing on the device. 2) Allocate the object from a second kernel, save the device memory pointer to the object

C++ vtable resolving with virtual inheritance

余生长醉 提交于 2019-12-06 05:06:30
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, because there's only one set of functions to pick from? Forgive me if this is an stupid question - as I said

compiler's detail of this pointer, virtual function and multiple-inheritance

余生长醉 提交于 2019-12-06 02:58:39
问题 I'm reading Bjarne's paper: Multiple Inheritance for C++. In section 3, page 370, Bjarne said that "The compiler turns a call of a member function into an "ordinary" function call with an "extra" argument; that "extra" argument is a pointer to the object for which the member function is called." I'm confused by the extra this argument. Please see the following two examples: Example 1 :(page 372) class A { int a; virtual void f(int); virtual void g(int); virtual void h(int); }; class B : A

C++ Base constructor calling with parameter that will be constructed in the derived constructor

流过昼夜 提交于 2019-12-06 02:57:07
问题 QUESTION 1) class Base { Base(std::string name); virtual std::string generateName(); } class Derived : Base { Derived(); virtual std::string generateName(); } here comes the question : what method will be called on generateName() ? Derived :: Derived : Base(generateName()) { //what method will be called on generateName() ? } QUESTION 2) how should i make it? if the default constructor must accept a parameter, but i need to generate that parameter in the Derived constructor? 回答1: First, the

Why can't the virtual function table pointer (vfptr) be static in C++?

半腔热情 提交于 2019-12-06 02:54:16
问题 If the virtual function table is the same for all objects of the class, then why can't the pointer to that table (vfptr) be static and be shared across all the objects? 回答1: The vtable is essentially static. But you need a vptr member actually inside the object to do virtual dispatch and other RTTI operations. On a vptr implementation, this C++ code: class Base { public: virtual void f(); }; class Derived : public Base { public: virtual void f(); }; may act similarly to something like this:

g++ “because the following virtual functions are pure” with abstract base class

我的未来我决定 提交于 2019-12-06 01:16:36
问题 Here is my example code which produces the error: struct Impl { int data_size_; int find(int var){return 0;} int get(int rowid){return 0;} }; class Container { public: Container() {} virtual ~Container() {} virtual int get_size() = 0; virtual int get(int rowid) = 0; }; class SortedContainer : virtual public Container { public: virtual int find(int var) = 0; }; class ContainerImpl : public Container { protected: Impl impl_; public: int get_size() {return impl_.data_size_;} int get(int rowid)

Virtual constructor idiom and factory design

别说谁变了你拦得住时间么 提交于 2019-12-06 00:51:29
In virtual constructor idiom there are virtual functions which returns new object OR copy of the object using virtual functions. But then to call these virtual functions polymorphic way, you must have object of that class created using actual constructor. In design pattern context, it means client is aware of the type of object before using polymorphic way of object creation? The client doesn't necessarily have to be aware of the concrete type. For example, consider this hierarchy: struct Base { virtual ~Base(); virtual Base * clone() const = 0; static Base * create(std::string const &); // ..