class

Difference between defining a member in __init__ to defining it in the class body in python?

What is the difference between doing class a: def __init__(self): self.val=1 to doing class a: val=1 def __init__(self): pass ...

Accessing parent variables in child method

Hi, I currently have two classes, one called Dog, one called Poodle. Now how can I use a variable defined in Dog from the Poodle class. My code is as follows: class dog { protected static $name = ''; function __construct($name) { $this->name = $name } } class Poodle extends dog { functi...

proper way to get all users using OOP

Hello, ive got a user class where i can get the name, date of birth etc of the user... (below) class user { private $id; private $name; private $dob; private address; function __construct($id) { $this->id = $id } } i was just wondering what the best practice to get all users. do i create a function...

Can the attributes of a class be an array?

I'm new to OOP, so please bear with me if this is a simple question. If I create a class, which has attributes "a", "b", and "c", is it possible for the attributes to be an array, such that attribute a[2] has a meaning? ...

Initialize custom class according to user selection

Hi, I have a navigation based application with two levels, in the second level the user select an option which should cause initialization and loading of the proper Nib file (there is a Nib file for every available selection). Now I'm doing the initialization in a switch, based on the user selection. The problem is that I'm adding Nibs...

Can I delete a dynamically allocated class using a function within that class?

I'm writing a state manager for a game. I've got most of the logic down for how I want to do this. I want states, which will be classes, to be handled in a stack in the StateManager class. Each state will have pause functions, and the stack will be an STL stack. When a state is done with what it needs to do (example: from the pause scre...

PHP: Need to pass variables/functions in a class function for printing layout header! How?

I have a class Page() that I can use to print the (layout) header with. With the function loadHeader($title) I want to be able to print it on all my pages. The actual code for the header is stored in header.inc.php. Now before the header I also want certain variables (like one which maintains a database connection) to be passed along ...

php - any way to access properties of an already instantiated class from another script without reinstantiating it?

Hello guys. I have page main.html which is a client application for a specific server. The main.php is an window with three frames. main.html <frameset frameborder=no border=0> <frame name='top1' src='top1.php' frameborder=no scrolling=no> <frame name='top2' src='top2.php' frameborder=no scrolling=no> <frame name='firstpage...

PHP OOP question

Hi all, i was just looking for a bit of advice, currently my DB design is that one user has many blog postings. Now i have a user class and a blog class. However im not sure about the proper way to get all blog posts for that user. Do i create a getAllBlogs() function in the user class which returns blog objects or do i create a main...

How do I get a PHP class constructor to call its parent's parent's constructor

I need to have a class constructor in PHP call its parent's parent's (grandparent?) constructor without calling the parent constructor. // main class that everything inherits class Grandpa { public function __construct() { } } class Papa extends Grandpa { public function __construct() { // call Grandpa's ...

What are the c# equivalents of of Java's getClass(), isAssignableFrom(), etc.?

I am translating from Java to C# and have code similar to: Class<?> refClass = refChildNode.getClass(); Class<?> testClass = testChildNode.getClass(); if (!refClass.equals(testClass)) { .... } and elsewhere use Class.isAssignableFrom(Class c)... and similar methods Is there a table of direct equivalents for class comparsion and prope...

Javascript - get class owner of a function(method)

Hi, there is a way to know what class own a function? Example: function globalFunc(){ //alert MyObject } function MyObject(){ } MyObject.prototype.test=function(){ globalFunc(); } var o=new MyObject(); o.test(); //alert MyObject Now im using this workaround: function globalFunc(){ alert(globalFunc.caller.__class__); } function...

AspectJ problem

Hi I am new to AspectJ and I would like to find out if creating variants of a class using Aspects - I will create another instance of the class as well? ...

Free library like Java's Robot class for C++

Is there a free library that has the same features of Java's Robot class for C++? http://java.sun.com/javase/6/docs/api/java/awt/Robot.html ...

Is it possible to have 2 Base class's which already inherit from something inherit or know of a third common class?

I have 2 class's Class 1. public class BaseContentPage : System.Web.UI.Page { } Class 2. public class BaseUserControl : System.Web.UI.UserControl { } And now i want them to be aware of this class. public class BaseCommon { public string Variable1 { get; set; } public string Variable2 { get; set; } public string Variable...

C++ static constant string (class member)

Hi guys. I'd like to have a private static constant for a class (in this case a shape-factory). I'd like to have something of the sort. class A { private: static const string RECTANGLE = "rectangle"; } Unfortunately I get all sorts of error from the C++ (g++) compiler, such as: ISO C++ forbids initialization of member ...

VB.NET need a class property to be a list array

Stack Overflowers: I have been racking my brain trying to get an List(of T) type array to be the property of a class. I know there has to be a simple way of doing it and I can't find a good example on google. Everytime I create a class that I think will work I get the "Object reference not set to an instance of an object" error when I...

How to work (portably) with C++ class hierarchies & dynamic linked libraries

Ok, so I know portability is not the strong point of C++, but I have to get my code running on both Mac&Windows. I've come up with a solution, but it's not perfect, and I'm interested to see if there is someone out there who can suggest a better one. I need to us a class hierarchy in several DLLs/bundles - e.g., I have an abstract base ...

Is it possible to choose the effect for a switchClass jQuery UI function?

I would like to add a subtle and quick fadeOut and FadeIn effect to a button change through switchClass. jQuery("a#btnPause").switchClass(pauseClass,playClass,200); The effect used by default is a slideLeft. If I would use standard jQuery, I would like to put an effect on addClass and removeClass, but is that possible? ...

PHP - Extension vs. Library vs. Class - when and why

I'm trying to accomplish a task and turns out that the code I need is packaged as a PHP extension, which according to what I've been told means I have to have root access to install it (I'm on shared hosting so that's a bit of a problem. I'll solve this problem later, but for now I'm trying to understand the difference between an exten...