FAQ Database Discussion Community


Warning: is_subclass_of() expects exactly 2 parameters, 3 given

php,parameters,documentation,subclass,user-documentation
The following code makes use of is_subclass_of, From the PHP documentation, there is a third parameter ($allow_string): bool is_subclass_of ( mixed $object , string $class_name [, bool $allow_string = TRUE ] ) But the following (which uses a redundant parameter as the third argument, to make the code more explicit),...

Base to derived class conversion does not result in null

c#,casting,subclass,base-class
As long as I know, we can't directly convert a base class to a derived (sub) class, because the base is not an instance of the derived and thus it'll result in null. I have two classes, one derives from the other. I'm trying to figure out why I can...

Cast an Object into a class

java,eclipse,class,subclass
I'm trying to cast an Object into a class instance. The Object of the classes instance should of course inherit all the methods. So here's my problem in sample code (2) because I can't exactly explain what I mean: Class Fish {} Class Dog {} class Instances() { private Fish...

Why doesn't a using-declaration work to solve the diamond proble​m?

c++,inheritance,subclass,using-directives,diamond-problem
Please consider the following code: struct A { void f() { } }; struct B1 : A { }; struct B2 : A { }; struct C : B1, B2 { void f() // works { B1::f(); } //using B1::f; // does not work //using B1::A::f; // does not work...

Swift UIButton Subclass not Showing on device or Simulator

ios,iphone,swift,uibutton,subclass
I have the following code and have declared IBDesignable. The DrawRect is shown perfectly well in Interface Builder, but not at all in the Simulator or on Device. Does anybody have any ideas why? import UIKit import QuartzCore @IBDesignable class VideoButton: UIButton { // Only override drawRect: if you perform...

How to make Superclass Method returns instance of SubClass

java,subclass
I have a class called Test and a class called SubTest who extends Text, I would like to have a method in the Test class who will returns the instance of SubTest when called, I would like to do : SubTest test = new SubTest().setTest("Hello!").setOtherTest("Hi!"); The setTest() and setOtherTest() methods...

Version of __CLASS__ that binds at run-time rather than at compile-time

php,runtime,subclass,classname,dynamic-binding
In the following PHP code I would like to replace the __CLASS__ magic constant in the Foo class with a function __X__() (or something similar) so that when the method hello() is called from an instance $bar of the Bar class, it prints hello from Bar (instead of hello from...

In C#, how could I get a class's inheritance distance to base class?

c#,subclass,distance
For example: I have the following classes: public class A {} public class B:A {} public class C:B {} public class D:C {} If there is a convenient method like to get a hierarchy distance to the base class(instead of testing D.IsSubclassOf(B)) to determine if D is closer to A,...

How to cast subclass object to superclass object

java,inheritance,casting,subclass,superclass
i have 2 classes, called superclass and subclass, i tried to cast the subclass object to superclass, but its seems does not work when i want to use the subclass object from the superclass. Please help to explain. Thanks. These are the code:- public class superclass { public void displaySuper()...

check if an item in an array list is an instanceof an object created in another class

java,arraylist,subclass
I'm using a foreach loop to go through an array list of objects that are all created in different subclasses of the same superclass, then if statements with instanceof boolean expressions to check which subclass the particular item the each loop is now on belongs to, but I don't think...

iOS Parse PFObject Subclassing with Swift Behaviour

ios,swift,parse.com,subclass,pfobject
I have a strange issue, my subclassing works in all my view controllers except one. I have imported everything that is required, but this one class is giving me the "Missing argument for parameter 'className' in call" My subclass import Foundation import Parse class Session : PFObject, PFSubclassing { class...

Creating a subclass for a UIView for reusability

ios,objective-c,uiview,subclass,uitapgesturerecognizer
I have a DiscoverViewController.h and .m files that have a function that displaces views of places to discover. I want to reuse this view in output viewcontrollers too. The code for the DicoverViewController.m with the uiview is below: for (PFObject *views in objects) { // Get the discoverr view setup...

Make class convertable to ndarray

python,arrays,class,numpy,subclass
Other than by subclassing (from list for example) how do I make a python object implicitly convertable to ndarray? Example: import numpy arg=[0,1,2] numpy.dot(arg,arg) # OK, arg is converted to ndarray #Looks somewhat array like, albeit without support for slices class A(object): def __init__(self, x=0,y=1,z=2): (self.x,self.y,self.z)=(x,y,z) def __getitem__(self, idx): if...

Java Atribute In Class and Subclass

java,class,attributes,subclass
I have the class Mappa with a subclass MappaFermi and an attribute mappaName (to choose from an Enum). I am trying to write a test whith the constructor MappaFermi() but i can't seem to write it correctly. public class Mappa { private Name mappaName; public Mappa (Name mappaName){ this.mappaName=mappaName; ......

Initialize base class’s fields in subclass constructor in C#

c#,constructor,subclass,base-class
I have a base class with three field, but instead of initializing its field the normal way like this: class ParentClass { public string Name { get; set; } public string Family { get; set; } public string Address { get; set; } public ParentClass(string Name, string Family, string Address)...

CSS subclass with and without space [duplicate]

css,subclass
This question already has an answer here: Difference between .classA.classB and .classA .classB in CSS? 2 answers Sorry for this noob question. What is the difference between .nav.left and .nav .left in CSS...

Is it OK to have an empty method?

java,oop,subclass,hierarchy,chess
Is it OK to have an empty method and have it overridden in its subclass(es)? This is how it would look like in my code. public class Rook() { public void voidCastleRight() { } } public class ShortRook() extends Rook { @Override public void voidCastleRight() { getPlayer().setkSC(false); //void King Side...

Can a subclass also be a superclass?

java,oop,inheritance,subclass,superclass
Can a subclass also be a superclass of another subclass in Java? Perhaps this is not the best example, but consider the following classes: public class Animal { } public class Dog extends Animal { } public class Cat extends Animal { } public class Siamese extends Cat { }...

Can't use enum in Java (Error:Can't find symbol)

java,enums,subclass
So I have a class file with just my enums that looks like this public class FactionNames { public enum Faction {AMITY, ABNIGATION, DAUNTLESS, EURIDITE, CANDOR}; } I have a class that uses these enums in a constructor which looks like this public Dauntless(String f, String l, int a, int...

PHP static factory method: dynamically instantiate instance of the calling class

php,static,runtime,subclass,factory
This PHP question is related to this question, but is a bit different. I have a static factory method called create() which instantiates a class instance. I want the method to dynamically instantiate an instance of the (sub)class on which it is called. So, the class it instantiates must be...

How can I determine the class of an object in Scala?

scala,subclass,instanceof,subtyping
I need to check that y is strictly an instance of bar AND NOT foo. How can I do this in Scala? trait foo {} trait bar extends foo {} val x = new foo {} val y = new bar {} x.isInstanceOf[foo] // true x.isInstanceOf[bar] // false y.isInstanceOf[bar] //...

Swift - Assign a NIB to self in class

ios,swift,subclass,xib,init
I am creating a UIView subclass for a notification dropdown banner. I am using a XIB to build out the view and want to assign that xib to the class when it initializes (i.e. avoiding having to do this from the calling ViewController). Since you can't assign to 'self' in...

Passing SuperClass constructor parameters to a SubClass?

inheritance,polymorphism,subclass,superclass
Just beginning to start implementing Super and Sub classes to our projects but I'm having a bit of a problem creating the Subclass constructors to allow for different types of accounts but following the same rules as the Superclass. Here is the constructor error I'm having. http://i.imgur.com/C3n7MxQ.png ...

How do I inherit a variable from a parent class? [duplicate]

java,variables,inheritance,parent-child,subclass
This question already has an answer here: Why does Eclipse require me to set (arbitrary) brackets in java code? 5 answers I have a subclass that needs to inherit a method and a variable, and I want to be able to make several instances of the subclass. However, I...

Applying function to subclass of Pandas DataFrame just returns DataFrame and now Subclass

python,inheritance,pandas,subclass
I am trying to subclass Pandas' DataFrame object. class AbundanceFrame(pd.DataFrame): 'Subclass of DataFrame used for creating simulated dataset with various component timeseries' def __init__(self, days,*args,**kw): 'Constructor for AbundanceFrame class, must pass index of timeseries' super(AbundanceFrame,self).__init__(index = days,*args,**kw) self.steps = 0 self.monotonic = 0 I have a number of other methods...

Swift: Declaring a constant in a subclass but still have a reference to it in the superclass?

ios,swift,constants,subclass,superclass
Let's say you had the class Apple with several subclasses. class Apple { let color = "" } class redDelicious :Apple { let color = "Red" } class grannySmith :Apple { let color = "Green" } func eatApple (appleToEat: Apple) { if appleToEat.color == "Red" { //do something } else...

java.lang.NullPointerException at com.sun.ejb.codegen.EjbOptionalIntfGenerator.generateSubclass(EjbOptionalIntfGenerator.java:280)

java-ee,nullpointerexception,glassfish,ejb,subclass
So I was using EJB to create users in DB. It worked. So after that I made a profile page that user can change. Unfortunately I'm hit with an NPE because the EJB can't load. So I've another @Stateless class and that I pretty much copy pasted to create this...

How to modify superclass variable from subclass?

java,class,subclass
In C++ I could use 1 class throughout multiple files and when I modify a value using a function from one file, it would change that value globally. In Java every file has to have it's own class; when I change a value using a method from one file, it...

Scala types class parameter: binding and subclassing - type mismatch

scala,class,parameters,subclass,type-mismatch
Noobe question. I have the following base trait (could be an abstract class): trait EState[S, A] { def retrn(a: A): EState[S, A] def runState(s: S): (A, S) } which I will later extend so: case class AState[S, A](val f: S => (A, S)) extends EState[S,A] { override def retrn(a: A):...

Fill a hashmap in superclass from subclass constructor in Java

java,javafx,subclass,abstract,superclass
I have an abstract superclass that is set up like this in JavaFX: abstract class View { protected static HashMap<String, View> viewMap; View(){ viewMap = new HashMap<String, View>(); } public static void addMap(String key, View value){ viewMap.put(key, value); } This super class includes the method: public static VBox goToView (final...

Creating Class relation

ruby,class,module,subclass,poset
Given an array of modules, what is the best way to return an array that describes the normalized (minimal) ordering relations between the modules? Each element of the array should be an array of pairs of modules that have child-parent relation. The child-parent order within each pair matters, but the...

Knockout - change an object's 'subclass' by setting a property on it

javascript,knockout.js,subclass
In Knockout, I have an array of Setting entities which may be of different types (i.e. 'subclasses' of the Setting entity). These types are dynamic, they may be changed by the user in the UI. Depending on what type the Setting entity is, it requires different object properties, and makes...

Subclass constructor with extra attributes

java,inheritance,constructor,attributes,subclass
If I have a class 'Dog' that extends another class 'Animal' and the Animal class has a constructor with several attributes like latinName, latinFamily etc. How should I create the constructor for the dog? Should I include all attributes that are found in Animal, and all the extra attributes that...

ios subclassing error casting subclass

objective-c,subclass,nsobject
I have a Widget class of nsobject with some properties and some methods, then I have a Widget subclass called Gallery, this class has some method and some properties... When I fetch data from web I save all data into Widget object, if one of this obj has a specific...

How to call subclass methods when subclass objects are stored in superclass array?

java,arrays,inheritance,subclass,superclass
{ Ship ships = new Ship(); CargoShip cargoShips = new CargoShip(); CruiseShip cruiseShips = new CruiseShip(); Ship[] allShips = {ships, cargoShips, cruiseShips}; allShips[0].setShipName("Boom"); allShips[0].setYearBuilt("1900"); allShips[1].setShipName("Bang"); allShips[1].setCargoCapaicty(200); allShips[2].setShipName("Bam"); allShips[2].setMaxPassengers(500); for (int i = 0; i < allShips.length; i++) { System.out.println(allShips[i]); } } So the Ship class is the super class while...

Why is a field with no modifier visible in a subclass? [duplicate]

java,subclass,visibility,access-modifiers
This question already has an answer here: In Java, what's the difference between public, default, protected, and private? 16 answers Why is a field with no modifier visible in a subclass? My super class: public class SuperClass { String s = "superString"; public void method(){ System.out.println("Super"); } } My...

using subclass's static variable in superclass

c++,variables,static,subclass
class Class1 { Class1() { Class2::counter++;} } class Class2: public Class1 { public: static int counter; } The above is an example of what I am trying to do. I am trying to use a static variable of a subclass in the superclass but that gives me a compiler error...

Expose a protected Objective-C instance variable to subclass

ios,objective-c,subclass,instance-variables
I am subclassing a pod's class, and in this class there's a private instance variable that I want to expose and use within my class: @interface MySuperClass () { UIScrollView *_scrollView; } Usually with exposing a private member or method, I would use a category like someone previously mentioned here,...

c# - Unique instance of a subclass

c#,interface,singleton,instance,subclass
I'm asking the question here cause i'm not finding the answer... Maybe i'm not looking for the right terms... My question is pretty simple, I have an interface class in C#, the thing is that one of the requirements of the program is that one and only one instance of...

How do I change part of a parent class's constructor when inheriting from it?

java,inheritance,subclass
I've got some class and I want to make an object out of it. However, this class has a property set in its constructor that makes it unusable for me. I cannot edit this class's code as it exists in a very tight codebase. This property cannot be changed after...

How to refer to parent class of base class from sub-sub-base-class static method without specifying base class name

php,subclass,static-methods,superclass,base-class
In PHP, I want to call a static method in the parent of the parent class from the sub-sub-class, without referring to the parent class of the parent class's name (please see the comment in the code below): class Base { public static function helloStatic() { return "Hello base!\n"; }...

Prototype chains in ECMAScript 6

javascript,subclass,ecmascript-6,ecmascript-harmony
I recently came across this great post by Dr. Axel Rauschmayer: http://www.2ality.com/2015/02/es6-classes-final.html The following snippet roughly describes how ECMAScript 6 prototype chains work from an ECMAScript 5 point of view (section 4.2 of the original post): // ECMAScript 6 class Point { constructor(x, y) { this.x = x; this.y =...

Subclasses and inheritance

android,inheritance,subclass,superclass
Let's have I have 3 classes. The First one is the parent class, The second one is a subclass of the Parent class. And the third class is a extends the 2nd class, which is a subclass itself. Will the 3rd class inherit the methods from the parent class?

python child class __set__ not working

python,class,subclass
I was following the advice of "python cookbook" on topic "Implementing Data Model or Type System" and there's code as follows: class Descriptor(object): def __init__(self, name=None, **opts): self.name = name for key, value in opts.items(): setattr(self, key, value) def __set__(self, instance, value): instance.__dict__[self.name] = value class Unsigned(Descriptor): def __init__(self, name=None,...

Standard text colour by subclassing UILabel for use on a storyboard - (IBOutlet)

ios,objective-c,uilabel,subclass
I'm looking to create a standard look and feel within my App, where some UILabel have a specific textColor. I have several UILabel on my UIViewController, and in the viewDidLoad method I'm calling a function that sets the textColor property: [[CHToolKit sharedToolkit] uiLabelAppearanceFeatured:[self IBOLabelStepsRemaining]]; CHToolkit is a singleton I created...

Getting clone of superclass

swift,clone,subclass,superclass
Here is my playground snippet: class Box { func clone() -> Box { return Box() // <- how to return superclass here? } } class VBox:Box { } let vb = VBox() let cBox = vb.clone() // now cBox is a Box, not a VBox My clone function returns a...

What is merging 2 classes into 1 class where one class is a subclass of the other called?

java,class,intellij-idea,refactoring,subclass
I have: an abstract class A an abstract class B that extends A no other classes that extends A except B other class(es) that extend B To reduce the number of classes, I want A and B to be merged into one class, and let the other class(es) extend from...

Referring to a PHP superclass name via a magic constant / keyword or similar construct (avoiding naming the superclass in the derived class)

php,subclass,keyword,subclassing,magic-constants
The comments in the following code show what I am trying to accomplish, which is something very simple: I want to be able to refer to the name of the parent class using a PHP built-in constant (or other construct) such as __CLASS__, but which refers to the parent class...

Scala apply with no parameters

scala,subclass,apply
I want to create a program that generates random things when requested, such as letters in the below example. I've defined an abstract class with a companion object to return one of the subclasses. abstract class Letter class LetterA extends Letter { override def toString = "A" } class LetterB...

Class can`t declare type

java,class,jbutton,subclass
I am going through thenewboston's tutorials and I have an unexpected error. I have tried to do everything that Eclipse suggest, but can't figure it out where the problem is. this is my Main Class import javax.swing.JFrame; class Main { public static void main(String args[]) { Gui go = new...

How can I access the members of a subclass from a superclass with a different constructor?

c++,inheritance,constructor,subclass,superclass
I have the following class and typedef: class Object { protected: long int id; public: Object(void); ~Object(void) {}; long int get_id(void); }; typedef map<string, Object> obj_map; And then I have its child: class Image: public Object { private: path full_path; int x; int y; img image; public: Image(path p, int...

How can I specify which class an object in an array list of many different objects from different classes comes from

java,arraylist,foreach,subclass,instanceof
I've created a for each loop to go through all the objects in an array lists. The objects in this array list are constructed in different classes that are all subclasses of the same superclass. How can I refer to the subclass that the object belongs to within the body...

How to properly subclass (at least) 5 complex NPC's to have multiple instances of later

objective-c,ios8,sprite-kit,subclass,skspritenode
I'm trying to call instances (a random amount of: between 3-7) of an NPC class I created. I have 5 (planning to make more) of such different NPC classes and they all subclass SKSpriteNode. Rough layout of each class is unfortunately simple: a method defining the SKPhysicsBody of the NPC...

Create a subclass from parent class with relationships with an sti

ruby-on-rails,ruby-on-rails-3.2,subclass,sti
I would like to be able to create a Professor that inherits from User on the same form by selecting the correct role and according to this role be able to link and create the Professor relationships. So I did: User.rb class User < ActiveRecord::Base attr_accessible :institution_id, :email, :password, :password_confirmation,...

Why does an override method defined in a protocol get called in the parent class and not it's subclass?

swift,oop,subclass
I have a protocol: public protocol JSONMapper { func map(fromJSON json:JSON) -> Self } And a class Model, that all my model objects inherit from: class Model: JSONMapper { func map(fromJSON json: JSON) -> Self { return self } class func instances (fromJSON json:[JSON]) -> [AnyObject] { var objects =...

Can @ManagedBean and @XxxScope be placed in a base class?

jsf,jsf-2,subclass,managed-bean
I have two @ManagedBean (javax.faces.bean.ManagedBean), parent and child. The parent managed bean is not abstract because we have to give liberty to the developer to use the parent if enough or inherit it with a child that holds specifically funcionality. I have problems with the injections bean and the @PostConstruct...

Java: using setter of a subclass when creating an object of type Superclass

java,subclass,getter-setter,superclass
I have a superclass Person and two subclasses Man and Woman in subclass Man, I have an instance variable age: public class Man extends Person{ private double age; public final static double MIN_AGE = 0.0; public final static double MAX_AGE = 65.0; //no argument constructor public Man(){ super(); initAge(); //...

Java Enumerated Types Error

java,enums,subclass
so I have a base class where I define an enum variable with this block of code. enum Faction { AMITY, ABNIGATION, DAUNTLESS, EURIDITE, CANDOR }; And I'm trying to test to see if everything in my subclass works by using a driver. My constructor in my subclass looks like...

Changing const member within class

c++,initialization,const,subclass
I would like to let a const int be changed by a function within a class. class Parent { int currentIndex; private: initMember(const int& member) { member = currentIndex++; } } class Child { const int Member1; const int Member2; Child () { initMember(Member1); initMember(Member2); } } Who ever writes...

Swift - MyClass is not identical to NSManagedObject

swift,generics,core-data,subclass,nsmanagedobject
Can someone explain to me why the following playground code gives me the error EventEntity is not identical to NSManagedObject import UIKit import CoreData class Table<T: NSManagedObject> { func toFetchedResultsController() -> FetchedResultsController<T> { return FetchedResultsController<T>() } } class EventEntity: NSManagedObject { } class FetchedResultsController<T: NSManagedObject> { } class Factory<T: NSManagedObject>:...

Java Failure on JUnit Case Calling a Method from a Subclass

java,methods,junit,subclass
I have the constructor Alieni from the subclass Alieni of the class Settore that sets the name ALIENI from the enum Nome to a certain Settore (composed by the integers coordinataX and coordinataY). The test I'm trying to make is to verify that after running the method Alieni to a...

Access specific child class functions whose objects are in a template class vector

c++,templates,vector,subclass,multiple-inheritance
I'm new here and I hope you can help me! :) My problem is the following: First, I have this class diagram: diagram Additionally, I have another class Rocket which has a vector that should contain all the rocket-parts as pointers that I generate. My problem is that the Rocket...