class

Is this PHP class optimized for mysql database access?

I've wrote a quick PHP class to ease the access to a mysql database. The class works ok, and has a query() method that opens up the connection, executes the query and then closes the connection (I know that the connection is supposed to close by PHP itself after the script finishes, but I don't like to rely very much on that). From a pe...

'Object' named class in Ruby

Does it have any drawbacks if I use Object as a name for my class inside module? module Some class Object; end end ...

What does "operator = must be a non-static member" mean? (C++)

I'm in the process of creating a double-linked list, and have overloaded the operator= to make on list equal another: template<class T> void operator=(const list<T>& lst) { clear(); copy(lst); return; } but I get this error when I try to compile: container_def.h(74) : error C2801: 'operator =' must be a non-static member ...

Is it possible to create a "friend class" in C++?

I know it's possible to create a friend function in C++: class box { friend void add(int num); private: int contents; }; void add(int num) { box::contents = num; return; } But is there a way to create friend classes? NB: I know there are probably a lot of errors in this code, I don't use friend functions and am still pretty new to ...

Is it possible to declare a class without defining it? (C++)

I know the questions seems ambiguous, but I couldn't think of any other way to put it, but, Is it possible to do something like this: #include<iostream> class wsx; class wsx { public: wsx(); } wsx::wsx() { std::cout<<"WSX"; } ? ...

What do the Items on the properties tab of MSVC++ mean?

I was playing around with my MSVC++ compiler, and the properties tab for my point class said: IsAbstract - false IsInjected - false IsManaged - false IsSealed - false IsTemplate - false IsValue - false What do these mean, and why were all of them greyed out except IsAbstract and IsSealed? ...

Objective-C Default Argument Value

Hey there, quick question here. I'm sure there's a simple answer. Coming from PHP, I'm used to declaring a function with a default argument value like this: function myFunction ($array, $sort = FALSE) { } I the sort parameter wasn't filled, the function would continue with the default value of false. In Obj-C, is there a similar t...

C++ Passing a Copy of an Object vs. Passing a Pointer to an Object?

Here's a constructor for my Game class: // Construct a Game to be played with player on a copy of the board b. Game(const Board& b, Player* player) { ... } Here's how I'm using the constructor: Player p("Player Name"); Board b(6,3); Game g(b, &p); How does this work? Is b being copied? If I want to save a pointer to player, shou...

Pythonic Way to Initialize (Complex) Static Data Members

Hello, I have a class with a complex data member that I want to keep "static". I want to initialize it once, using a function. How Pythonic is something like this: def generate_data(): ... do some analysis and return complex object e.g. list ... class Coo: data_member = generate_data() ... rest of class code ... The func...

Javascript "classes" (no frameworks)

I'm doing my first javascript project that makes heavy use of objects. Because of how it works, nearly all the custom objects are done like this: namespaceobj = {}; namespaceobj.subobject = {}; namespaceobj.subobject.somefunction = function(arg, uments) { // Do Stuff } namespaceobj.subobject.somedata = 10; namespaceobj.othersubject ...

Enumerated data types and class APIs in C++

If you're supposed to encapsulate everything inside a class definition, how is it then possible to use enumerated data types with the class? For example I've just written the following code... enum PizzaType {DEEP_DISH, HAND_TOSSED, PAN}; enum PizzaSize {SMALL, MEDIUM, LARGE}; class Pizza { public: Pizza(); void set...

How to refer to an "owner class" in C++?

I have code that looks like this: template<class T> class list { public: class iterator; }; template<class T> class list::iterator { public: iterator(); protected: list* lstptr; }; list<T>::iterator::iterator() { //??? } I want to make the constructor of list::iterator to make iterator::lstptr point to the list it's ...

Run code on creation of a PHP class?

I want code to run whenever I create a new object. For example, see this: <?php class Test { echo 'Hello, World!'; } $test = new Test; ?> I want it to echo "Hello, World!" whenever I create a new instance of this object, without calling a function afterward. Is this possible? ...

Make PHP Object do different actions depending on variable name

For example, if let's say I have a database of users. I have a class that gets information form the database about these users. I want to make the class "self aware" of it's own name, like this: <?php class UserData { //[code that fetches the ID number from the variable name, and queries the database for info] } $user24 = new UserD...

Calling a class inside a class

I'm trying to write a class that when asked on, will call on a class and make it into a class member. Here's a quick example of what I mean: class foo{ myClass Class; foo(); }; foo::foo() { //Create the class and set it as the foo::Class variable } I'm sure this is actually an easy thing to do. Any help would be appreciated Tha...

Is there an issue to use int for class property?

When I started with Cocoa, I remember that I read somewhere that int/float and similar should not be used for class properties and to use NS* equivalents (like NSInteger). Is there a real hidden issue here why would that be better or it was just a voluntary coding rule by a person where I read that (and I can't for the life of me find w...

Advantages of prototype based OO over class based

Why is class based OO so popular instead of prototype based OO? Do they teach the latter in schools? Javascript is object based, but people use it mostly functionally, or via frameworks. I know that Sun has had some research on Self, but is there any other source of knowledge; preferably something that is accessible for self learned. I...

Java AOT + loading java classes dynamically

I'm building a plugin system for my application. I've read that anyone can decomple .class files and therefore I'm forced ot use a Ahead-Of-Time compiler (right?). The problem is that I need to load some plugin classes dynamically. Right now I'm loading all .class files in a folder and invoking a static method (I never create a object) a...

C# Application Settings not saving using custom class

Here's the class im trying to store [Serializable] [XmlRoot(ElementName = "Database", IsNullable = false, Namespace = "http://somesite.com")] class Database { [XmlAttribute(AttributeName = "Name")] public string Name { get; set; } [XmlAttribute(AttributeName = "Provider")] public DatabaseProvider Provider { get; se...

raising events in a static class

I have a windows form with a data grid bound to a datatable. On a button click, the data table is passed to a static class. private void btnSave_ItemClick(object sender, EventArgs e) { MyStaticClass.SaveData(DataTable dt); } internal static class MyStaticClass { internal static void SaveData(DataTable dt) { foreach(D...