class

Read class objects from file c++

眉间皱痕 提交于 2019-12-24 17:24:01
问题 I need to read class objects from file, but I don't know how. Here I have a class "People" class People{ public: string name; string surname; int years; private: People(string a, string b, int c): name(a),surname(b),years(c){} }; Now I would like to read peoples from .txt file and store them to objects of a class People. For instance, this is how my .txt file looks like: John Snow 32 Arya Stark 19 Hodor Hodor 55 Ned Stark 00 I think the best way to do this would be to create array of 4

Python Class Inheritance: Calling a function of a derivative class

一世执手 提交于 2019-12-24 17:18:31
问题 The my_car.drive_car() method is meant to update ElectricCar 's member variable condition to "like new" but still calls drive_car from the Car super class. my_car = ElectricCar("Flux capacitor", "DeLorean", "silver", 88) print my_car.condition #Prints "New" my_car.drive_car() print my_car.condition #Prints "Used"; is supposed to print "Like New" Am I missing something? Is there a more elegant way to override superclass functions? class ElectricCar inherits from the super class Car class Car

Problems inserting two different classes within the same frame into a notebook using Tkinter and Python

蓝咒 提交于 2019-12-24 16:58:17
问题 I have been trying inserting two different classes (in the code below "MyListbox" and "Calculation") within the same frame into a notebook using Tkinter and Python. Actually I Have not received any report from my computer saying where I am wrong. My computer doesn't show anything, not even a message. Can you help me solving this problem? Thanks in advance. Here is the code: import Tkinter from Tkinter import * from Tkinter import Tk, Text, BOTH, W, N, E, S from ttk import Frame, Button, Label

C++ Cannot call constructor ' ' directly

自闭症网瘾萝莉.ら 提交于 2019-12-24 16:41:56
问题 I'm working on some OpenCV code and developed it in VS 2008 on windows. I'm trying to run the code on Linux with g++ but I get the error "Cannot call constructor 'ImageProcessor::ImageProcessor' directly" for ImageProcessor and all of the other classes I have created. I've attempted to find a way to indirectly call the constructor, but to no avail. Any suggestion would be great. The code compiles and runs fine on Windows. if (x == 1){ cout <<"MODE SELECTED: IMAGE TESTING \n"; ImageProcessor*

Cannot get variable from Child back to Parent in JAVA (Options Window)

感情迁移 提交于 2019-12-24 16:34:01
问题 STARTED - 3:00PM UPDATE 1 - 5:36PM Apply Button in the Option() class: private void cmdApplyActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: hud.setTime(btnTxtTime); hud.setTemp(btnTxtTemp); hud.setSurface(btnTxtSurface); hud.setWeather(btnTxtWeather); hud.setRadiation(btnTxtRadiation); dispose(); } This is a section of the Option() Class. public class Options extends javax.swing.JFrame { public String btnTxtTime; public String btnTxtTemp; public String

Call class method on object of unknown class

[亡魂溺海] 提交于 2019-12-24 16:17:29
问题 I added a set of classes to an array, all which I know have the same superclass: [array addObject:[Africa class]]; [array addObject:[Brazil class]]; [array addObject:[France class]]; Later, I want to get the class object and call a superclass class method on it. Something like this: Class class = [array objectAtIndex:1]; (Country class) specificClass = class; I've tried a variation of different ideas, but can't figure out how to put that last line in code. 回答1: If I get you right you want a

Delphi 'private' clause (directive) does not work

自闭症网瘾萝莉.ら 提交于 2019-12-24 16:17:22
问题 I'm trying to check if my private procedures are really private. But it works the way it shouldn't. Please help me, maybe I missed something about how the incapsulation should work. This code should not work. I guess. But it works. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type tmyclass = class private procedure one; end; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private

Making custom class to behave like set

﹥>﹥吖頭↗ 提交于 2019-12-24 16:07:01
问题 I try to make a class containing file names in a folder. But I want it to behave like set. Now I have this: class Files(): def __init__(self, in_dir): self.in_dir = in_dir self.files = set(map(os.path.basename, glob.glob(self.in_dir + "/*.txt"))) def __add__(self, other): return self.files + other.files def __or__(self, other): return self.files | other.files def __and__(self, other): return self.files & other.files def __xor__(self, other): return self.files ^ other.files This work and I can

php - Access outer class from an anonymous callback

喜你入骨 提交于 2019-12-24 15:59:58
问题 I have a code like this: class Server { private $stopper; public function setStopper() { $this->stopper = TRUE; } public function startServer() { $consumer = new Consumer(); $consumer->onConsume(function($data) { global $consumer; // some processing if( ?? ) { // how to access stopper here?? $consumer->stop(); // also how to access stopServer() here?? } }); $consumer->consume(); } public function stopServer() { ... } } This code is in a file that should run forever unless the setStopper() is

How to convert Swift “switch case is …” block into loop oriented code?

蓝咒 提交于 2019-12-24 15:56:49
问题 I've got code that looks like this: class Base { func launch(code1: Int, code2: Int) -> Bool { return false } } class A: Base {} class B: Base {} class C: Base {} func trynext(obj: Base) -> Base? { switch obj { case is A: return B() case is B: return C() default: return nil } } Basically, I've got a lot (like 20) of subclasses of a common base class and I need to go through them one by one. These subclasses represent parsers and I'm trying them one after another to discover which parser