base-class

How to resolve “pure virtual method called”

此生再无相见时 提交于 2019-11-27 12:59:35
问题 I understand why this is happening, but I'm stuck trying to resolve it...here is what my code is doing when the error is generated (thus, leading to a crash) when my program exits... pure virtual method called SomeClass::~SomeClass() { BaseClassObject->SomePureVirtualMethod(this); } void DerivedClass::SomePureVirtualMethod(SomeClass* obj) { //Do stuff to remove obj from a collection } I never have a call to new SomeClass but I have a QList<SomeClass*> which I append SomeClass* objects to. The

How can I polymorphic deserialization Json String using Java and Jackson Library?

元气小坏坏 提交于 2019-11-27 11:42:22
I've some classes A, B, C they all inherit from class BaseClass. I've a String json that contains the json representation of the A, B, C or BaseClass. I want to have some way to deserialize this String to the BaseClass (polymorphic deserialization). Something like this BaseClass base = ObjectMapper.readValue(jsonString, BaseClass.class); jsonString could be Json String representation of any of A, B, C, or BaseClass. Programmer Bruce It's not clear what problem the original poster is having. I'm guessing that it's one of two things: Deserialization problems with unbound JSON elements, because

Invalide use of incomplete type Qt

笑着哭i 提交于 2019-11-27 08:46:37
问题 I have a little problem : finddialog.h #ifndef FINDDIALOG_H #define FINDDIALOG_H class QDialog; class QWidget; class QLineEdit; class QPushButton; class QCheckBox; class QLabel; class FindDialog : public QDialog { Q_OBJECT public: FindDialog(QWidget *parent); private slots: void findClicked(); void enableFindButton(const QString &text); signals : void findNext(const QString &str, Qt::CaseSensitivity cs); void findPrev(const QString &str, Qt::CaseSensitivity cs); private: QLabel *findLabel;

.NET: Unable to cast object to interface it implements

依然范特西╮ 提交于 2019-11-27 04:32:37
问题 I have a class (TabControlH60) that both inherits from a base class (UserControl) and implements an interface (IFrameworkClient). I instantiate the object using the .NET Activator class. With the returned instance, I can cast to the UserControl base class, but not to the interface. The exception I get is below the code snipet. How do I cast to the interface? object obj = Activator.CreateInstance(objType); Type[] interfaces = obj.GetType().GetInterfaces(); // contains IFrameworkClient m_Client

How to hide an inherited property in a class without modifying the inherited class (base class)?

妖精的绣舞 提交于 2019-11-27 01:56:56
If i have the following code example: public class ClassBase { public int ID { get; set; } public string Name { get; set; } } public class ClassA : ClassBase { public int JustNumber { get; set; } public ClassA() { this.ID = 0; this.Name = string.Empty; this.JustNumber = string.Empty; } } What should I do to hide the property Name (Don't shown as a member of ClassA members) without modifying ClassBase ? BenAlabaster I smell a code smell here. It is my opinion that you should only inherit a base class if you're implementing all of the functionality of that base class. What you're doing doesn't

C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass

ε祈祈猫儿з 提交于 2019-11-27 00:04:58
问题 What is the recommended approach to naming base classes? Is it prefixing the type name with " Base " or " Abstract " or would we just suffix it with "Base"? Consider the following: type: ViewModel e.g. MainViewModel , ReportViewModel base class: BaseViewModel or ViewModelBase or AbstractViewModel Also consider: type: Product e.g. VirtualProduct , ExpiringProduct base class: BaseProduct or ProductBase or AbstractProduct Which do you think is more standard? class Entity : EntityBase { } or

Understanding virtual base classes and constructor calls

别说谁变了你拦得住时间么 提交于 2019-11-26 23:20:32
问题 I'm a bit confused about how virtual base classes work. In particular, I was wondering how the constructor of the base class gets called. I wrote an example to understand it: #include <cstdio> #include <string> using std::string; struct A{ string s; A() {} A(string t): s(t) {} }; struct B: virtual public A{ B(): A("B"){} }; struct C: virtual public A {}; struct D: public B, public C {}; struct E: public C, public B {}; struct F: public B {}; int main(){ D d; printf("\"%s\"\n",d.s.c_str()); E

Base template class data members are not visible in derived template class?

[亡魂溺海] 提交于 2019-11-26 21:51:36
问题 Consider the following C++ code, template <typename Derived> struct A { bool usable_; }; template <typename Derived> struct B : A< B<Derived> > { void foo() { usable_ = false; } }; struct C : B<C> { void foo() { usable_ = true; } }; int main() { C c; } I got compilation error: In member function void B<Derived>::foo() : template_inherit.cpp:12: error: 'usable_' was not declared in this scope. Why is that ? Any good fix ? 回答1: That's because usable_ is a non-dependent name, so it is looked up

Does delete on a pointer to a subclass call the base class destructor?

只谈情不闲聊 提交于 2019-11-26 19:14:59
I have an class A which uses a heap memory allocation for one of its fields. Class A is instantiated and stored as a pointer field in another class ( class B . When I'm done with an object of class B, I call delete , which I assume calls the destructor... But does this call the destructor of class A as well? Edit: From the answers, I take that (please edit if incorrect): delete of an instance of B calls B::~B(); which calls A::~A(); A::~A should explicitly delete all heap-allocated member variables of the A object; Finally the memory block storing said instance of class B is returned to the

Cast base class to derived class python (or more pythonic way of extending classes)

僤鯓⒐⒋嵵緔 提交于 2019-11-26 15:19:42
I need to extend the Networkx python package and add a few methods to the Graph class for my particular need The way I thought about doing this is simplying deriving a new class say NewGraph , and adding the required methods. However there are several other functions in networkx which create and return Graph objects (e.g. generate a random graph). I now need to turn these Graph objects into NewGraph objects so that I can use my new methods. What is the best way of doing this? Or should I be tackling the problem in a completely different manner? If you are just adding behavior, and not