derived-class

Qt Widgets and derived classes

我怕爱的太早我们不能终老 提交于 2019-12-18 09:44:07
问题 I am wondering if there is a way to do this. I create a Qt Application (using Creator 3.6.1, Qt 5.6.0). I add a widget to the main window. For example a QGraphicsView called myView. I create a C++ class derived from QGraphicsView (called DerivedView) code of DerivedView class: class DerivedView : public QGraphicsView { ... I would like my new DerivedView class to control this widget. I can access a pointer to the object through ui->myView. Is there any way to do get my derived class to work

Disabling inherited method on derived class

Deadly 提交于 2019-12-17 10:56:36
问题 Is there any way to, in a Java derived class, "disable" a method and/or field that is otherwise inherited from a base class? For example, say you have a Shape base class that has a rotate() method. You also have various types derived from the Shape class: Square , Circle , UpwardArrow , etc. Shape has a rotate() method. But I don't want rotate() to be available to the users of Circle , because it's pointless, or users of UpwardArrow , because I don't want UpwardArrow to be able to rotate. 回答1

How to define sealed class in C++?

限于喜欢 提交于 2019-12-17 10:24:17
问题 How to stop the class to be inherited by other class. 回答1: C++11 solution In C++11, you can seal a class by using final keyword in the definition as: class A final //note final keyword is used after the class name { //... }; class B : public A //error - because class A is marked final (sealed). { // so A cannot be derived from. //... }; To know the other uses of final, see my answer here: What is the purpose of the "final" keyword in C++11 for functions? C++03 solution Bjarne Stroustrup's

How to define sealed class in C++?

℡╲_俬逩灬. 提交于 2019-12-17 10:22:42
问题 How to stop the class to be inherited by other class. 回答1: C++11 solution In C++11, you can seal a class by using final keyword in the definition as: class A final //note final keyword is used after the class name { //... }; class B : public A //error - because class A is marked final (sealed). { // so A cannot be derived from. //... }; To know the other uses of final, see my answer here: What is the purpose of the "final" keyword in C++11 for functions? C++03 solution Bjarne Stroustrup's

Derived and base class, can I set the base explicitly?

孤街浪徒 提交于 2019-12-13 12:24:50
问题 public class SuperCar: Car { public bool SuperWheels { get {return true; } } } public class Car { public bool HasSteeringWheel { get {return true;} } } How can I set the base class for the derived Supercar? For example, I want to simply set SuperCars base class like this: public void SetCar( Car car ) { SuperCar scar = new SuperCar(); car.Base = car; } Basically, if I have Car objects, I do not want to manually iterate through every property of the car in order to setup the SuperCar oject,

How to derive from/extend a recursive class

给你一囗甜甜゛ 提交于 2019-12-13 05:25:37
问题 I have a recursive class, a kind of tree, that has instances of itself as member variables. For example: template<class T> class Tree { public: /* Constructors, etc. */ protected: T m_value; Tree<T> *leftChild; Tree<T> *rightChild; }; If I want to add a method that prints all the values using an in-order traversal, I could do this: template <class T> void Tree<T>::printInOrder() { leftChild->printInOrder(); std::cout << m_value << std::endl; rightChild->printInOrder(); } But what if, for

How can I derive classes from a base class that is encapsulated in a manager class?

核能气质少年 提交于 2019-12-13 02:21:48
问题 I have a ManagerClass that manages classes that derive from an abstract BaseClass. I need it so that only the ManageClass can access certain methods on the BaseClass. I also need certain methods to be accessible outside the scope of the ManagerClass. Since C# doesn't have friends, I'm encapsulating the BaseClass inside the ManagerClass. The problem: BaseClass is not accessible to derive from Making BaseClass public,means allowing DoStuff() and DoOtherStuff() to be called from outside the

XMLSerialization: The type of the argument object 'Sw' is not primitive

流过昼夜 提交于 2019-12-12 13:28:44
问题 I'm trying to serialize an object to an XML file, but am getting the above error. The problem seems to be with objects that contain a list of a base class but is populated by objects derived from the base class. Example code is as follows: public class myObject { public myObject() { this.list.Add(new Sw()); } public List<Units> list = new List<Units>(); } public class Units { public Units() { } } public class Sw : Units { public Sw(); { } public void main() { myObject myObject = new myObject(

How to implement clone in a pure abstract class?

拈花ヽ惹草 提交于 2019-12-12 10:20:09
问题 So I want to override the pure abstract method in my derived classes but I got this error. Can someone help me see what happened and how can I complete it. My Device class; class Device { public: Device(); Device(const Device& orig); virtual ~Device(); virtual Device Clone() = 0; } And my derived class; class Radar : public Device { public: Radar(); // Radar(const Radar& orig); // commenting so the compiler using its default copy constructor virtual ~Radar(); Radar Clone(); }; Source file for

How to pass List<DerivedClass> when param type is List<BaseClass>?

感情迁移 提交于 2019-12-12 07:26:58
问题 How can i pass a list which is a list of DerivedObjects where the Method is expecting a list of BaseObjects. I am converting the list .ToList<BaseClass>() and am wondering if there is a better way. My second problem is the syntax is incorrect. I am trying to pass the list byref and i am getting an error: 'ref' argument is not classified as a variable How can I fix these two problem? thanks. public class BaseClass { } public class DerivedClass : BaseClass { } class Program { static void Main