class

Should I have to have duplicate values in VBA class objects?

∥☆過路亽.° 提交于 2020-01-14 09:48:26
问题 I've been using VBA class modules in excel for a while now, but I'm not sure that I am creating them correctly. I normally create module level variables for the class and then property let and get functions. For example: Private msRegion As String Property Get Region() As String Region = msRegion 'Return the Region End Property Property Let Region(ByVal sRegionName As String) msRegion = sRegionName 'Set the Region End Property When I look at the objects in the local window I notice that for

Deep class inheritance hierarchy — bad idea?

为君一笑 提交于 2020-01-14 09:33:08
问题 hoping a grandmaster can shed some light. Very high overview is that I am no beginner to coding, but still new to OOP. This set of message classes is at the heart of a large simulation application we're writing, and I don't want to do it stupidly--this interface cuts the application in half, from sequencer to executer and vice-versa. My question is whether or not it's a bad idea to have an inheritance hierarchy this deep (image is not yet fleshed out, might go 5 or 6 deep in the end). This is

Default constructor defined with default arguments outside the class definition, why does this work? and what happens with templates involved?

寵の児 提交于 2020-01-14 09:00:32
问题 I am aware this is bad form and that default-values should be specified in the declaration, but if you would please indulge me for a moment.. why does this compile? and what is happening exactly? #include <iostream> using namespace std; class test { public: test(int n); }; test::test(int n = 666) { cout << n; } int main() { test t; cin.sync(); cin.ignore(); return 0; } Output: 666 .. how do templates affect the same piece of code? template <class T> class test { public: test(int n); };

Parse.com: with parseUser, how can I save data in a column I created in parse from the class?

二次信任 提交于 2020-01-14 08:06:09
问题 I am using Android Studio for my app and Parse for my database... and on the create an account page I have, it allows the user to enter in first name, last name, email, username, and password. But my code is using parseUser... I don't know how to set the first and last name in the database. I know setUsername, setPassword, setEmail is a part of it... but what about if you make a column in Parse? How can you add this in your class? This is a part of my code, what it looks like...my problem is

Why is this destructor being called immediately after creation?

痞子三分冷 提交于 2020-01-14 07:36:07
问题 I have the following class: class FixedByteStream { public: FixedByteStream() : size(0), address(NULL), existing(false) {} FixedByteStream(int length) : existing(false) { size = length; address = new char[length]; } FixedByteStream(int length, char* addr) : existing(true) { size = length; address = addr; } FixedByteStream(string* str, bool includeNull = false) : existing(true) { size = (*str).length(); address = const_cast<char*>((*str).c_str()); if (includeNull){ ++size; } } ~FixedByteStream

How can I clear class variables between rspec tests in ruby

戏子无情 提交于 2020-01-14 07:06:07
问题 I have the following class: I want to ensure the class url is only set once for all instances. class DataFactory @@url = nil def initialize() begin if @@url.nil? Rails.logger.debug "Setting url" @@url = MY_CONFIG["my value"] end rescue Exception raise DataFactoryError, "Error!" end end end I have two tests: it "should log a message" do APP_CONFIG = {"my value" => "test"} Rails.stub(:logger).and_return(logger_mock) logger_mock.should_receive(:debug).with "Setting url" t = DataFactory.new t =

How have you dealt with the lack of constructors in VB6?

断了今生、忘了曾经 提交于 2020-01-14 06:56:21
问题 VB6 classes have no parameterized constructors. What solution have you chosen for this? Using factory methods seems like the obvious choice, but surprise me! 回答1: I usually stick to factory methods, where I put the "constructors" for related classes in the same module (.BAS extension). Sadly, this is far from optimal since you can't really limit access to the normal object creation in VB6 - you just have to make a point of only creating your objects through the factory. What makes it worse is

PHP Don't allow object to instantiate more than once

浪子不回头ぞ 提交于 2020-01-14 05:35:10
问题 I have an abstract class that is inherited by a number of other classes. I'd like to have it so that instead of re-instantiating (__construct()) the same class each time, to have it only initialize once, and utilize the properties of the previously inherited classes. I'm using this in my construct: function __construct() { self::$_instance =& $this; if (!empty(self::$_instance)) { foreach (self::$_instance as $key => $class) { $this->$key = $class; } } } This works - sort of, I'm able to get

AS3 Passing data between objects/classes

妖精的绣舞 提交于 2020-01-14 05:18:12
问题 So i a building a categorized menu of different foods. I have a class for "categories" (buttons) which essentially will return a string "salads", "drinks", etc. I now have another class "menuItems" for items within categories and this handles sizes such as "small", "med", "large", etc. My problem now is that when i return "salads", i want to invoke an array which contains all the elements of salads, send it to menuItems which will populate the menu. So far i have both the category objects and

Why can't nonempty slots be used with int, tuple, bytes subclasses?

爱⌒轻易说出口 提交于 2020-01-14 03:43:06
问题 This is explicitly documented in the reference manual: Nonempty __slots__ does not work for classes derived from “variable-length” built-in types such as int, bytes and tuple. and it is the case, writing: class MyInt(int): __slots__ = 'spam', results in: TypeError: nonempty __slots__ not supported for subtype of 'int' why is this, though? Why can empty slots be used but non empty ones fobidden? 回答1: __slots__ reserves space at a fixed offset in an object’s layout for each slot defined. (This