class

Recommended way for passing data connection to a PHP class / method?

我是研究僧i 提交于 2020-01-15 09:44:48
问题 As of right now I have a database connection string included at the top of each of my pages. I'm then passing my database connection to the methods in my class like this: public function select($db) { //Code here } Code on page: $login_user->select($db); My thought is that if I ever want to query a different database I can just create a new connection string in my include file called $db2 and then I just pass that value instead of $db. Is this a standard way of doing this or do you have a

Inherit and overload default constructor

為{幸葍}努か 提交于 2020-01-15 09:10:08
问题 I've been searching for this and I'm amazed I haven't found anything. Why can't I inherit a base class constructor using using declaration and add an overload in the derived class? I'm using Visual C++ 2013, the base class constructor is ignored when default-constructing b : error C2512: 'B' : no appropriate default constructor available I've dealt with this by re-defining the constructors, but I don't like that. This is just a minimal example, it wouldn't bother me if I had only one base

“can't find main class” error in terminal but not in eclipse

依然范特西╮ 提交于 2020-01-15 07:07:19
问题 This program take real life objects and its weights and sorts it based on alphebatical order and then number-wise But the problem is that when I run this app in Eclipse (haven't tried in NetBeans), it runs fine, but when I compile and try to run it in terminal, it doesn't work and comes with error, "could not find main class" Keep in mind my java file and class file are in the same folder, so the directory is not the problem public class testMain { public static void main(String[] args) { /

How to run .java file with Variable Name

你离开我真会死。 提交于 2020-01-15 06:56:10
问题 I'm trying to make a program based off of the Pebble Smartwatch Operating System. I have a text file called PebbleOS_Faces.txt which has all the names of the different watch faces I will have on the watch. I use PrintWriter to convert the content into a .java file, and then I compile it using the code I got from this post. It gets compiled into the build/classes/pebbleos folder (I'm using Netbeans for Mac, in case that makes a difference), next to all of the other classes. I've confirmed that

Python - Add days to an existing date

前提是你 提交于 2020-01-15 06:35:06
问题 Obviously this is homework so I can't import but I also don't expect to be spoon fed the answer. Just need some help on something that's probably pretty simple, but has had me stumped for too many hours now. I have to add days to an existing date in python. Here is my code: class Date: """ A class for establishing a date. """ min_year = 1800 def __init__(self, month = 1, day = 1, year = min_year): """ Checks to see if the date is real. """ self.themonth = month self.theday = day self.theyear

Python assertRaises on user-defined exceptions

主宰稳场 提交于 2020-01-15 05:15:30
问题 The following question was triggered by the discussion in this post. Assume two files ( foobar.py and foobar_unittest.py ). File foobar.py contains a class ( FooBar ) with two functions ( foo and bar ). Function bar raises a built-in exception, function foo a user-defined exception. # foobar.py class MyException(Exception): pass class FooBar: def __init__(self): pass def bar(self): raise ValueError('Hello World.') def foo(self): raise MyException('Hello World.') . # foobar_unittest.py import

OrderedDict won't sort within a class

二次信任 提交于 2020-01-15 04:15:10
问题 I have a parent class, and I want to keep a registry (in the form of a dictionary) of all instances of its sub-classes. Easy, but I want the registry to sort itself based on its keys, which are the arguments of the 2 sub-classes on initialisation. This is my code in simplified form: from collections import OrderedDict class Parent: _registry = OrderedDict() def __init__(self): # add each sub-class instance to the registry & sort the registry self._registry.update({self._num:self}) self.

How to make variable global across entire class

本秂侑毒 提交于 2020-01-15 03:31:04
问题 Very simple question, is it possible to make a variable that is retrieved from outside of a class, 'global' to the whole class so that I do not have to call the 'global $variable' at the beginning of each method? This is what I am currently doing: class test{ public function testing(){ global $globalVariable, // Do something } public function testing_two(){ global $globalVariable, // Do something } } In other words, can I import variables into the construct function and therefore make them

Interfaces, Classes and Code Smell

时光怂恿深爱的人放手 提交于 2020-01-15 03:08:45
问题 Suppose I have the following interfaces : public interface GameObject { void viewDetails(); } public interface Weapon extends GameObject { void attack(); } //A weapon is not the only item reloadable. A container could be refilled. public interface Reloadable extends GameObject { void replenish (final int amount); } and Implementation: public final class ReloadableWeapon implements Reloadable, Weapon { private String weaponName; private int numberofbullets; public ReloadableWeapon(String name,

Use class instance as generic type

本小妞迷上赌 提交于 2020-01-14 22:45:13
问题 Is there any way of using SomeClass.class as the generic type for a type? For example I have an enum: enum MyEnum { FOO(String.class); private Class fooClass; private MyEnum(Class fooClass) { this.fooClass = fooClass; } public Class getFooClass(){ return fooClass; } } And then somewhere in my code: List<MyEnum.FOO.getFooClass()> list = new ArrayList<>(); 回答1: No. Generics are evaluated at compile time while the value of this call: MyEnum.FOO.getFooClass() is only known at runtime. 回答2: