class

How do you pass a member function pointer?

I am trying to pass a member function within a class to a function that takes a member function class pointer. The problem I am having is that I am not sure how to properly do this within the class using the this pointer. Does anyone have suggestions? Here is a copy of the class that is passing the member function: class testMenu : p...

Php redefine Class Methods OR Class

Is there any way to redefine a class or some of it's methods without using typical inheritance ex: class third_party_library { function buggy_function() { return 'bad result'; } function other_functions(){ return 'blah'; } } what can I do to replace the buggy_function? Obviously this is what i would lik...

PHP Class Database Connection Scope Issue

For a new project that I'm doing in PHP I've created an SQLMethods class to connect to the database and perform queries. Tonight was the first night that I actually got to test it (I wrote it a week or so ago and forgot about it) and an unexpected error occured: When it was calling my ExecuteQuery() function, it wouldn't use the database...

C++ class initialisation containing class variable initialization

I noticed some code of a colleague today that initialized class variables in the initialization. However it was causing a warning, he says because of the order they are in. My question is why is it better to do variable initialization where it currently is and not within the curly brackets? DiagramScene::DiagramScene( int slideNo, QRe...

Exposing Member Objects As Properties or Methods in .NET

In .NET, if a class contains a member that is a class object, should that member be exposed as a property or with a method? ...

What is better practice when programming a member function?

I have seen member functions programed both inside of the class they belong to and outside of the class with a function prototype inside of the class. I have only ever programmed using the first method, but was wondering if it is better practice to use the other or just personal preference? ...

Stopping a function from been overridden in Delphi

How do I stop a function/procedure in a superclass from been overridden in a subclass in Delphi (2007)? I want to mark it so it can not be altered, I believe there is a final keyword but can not for the life of me find the documentation for it, so I am not 100% sure that's what I need. ...

Is there a way to implement algebraic types in Java?

Is it possible, in Java, to enforce that a class have a specific set of subclasses and no others? For example: public abstract class A {} public final class B extends A {} public final class C extends A {} public final class D extends A {} Can I somehow enforce that no other subclasses of A can ever be created? ...

How would I implement a Python bit map?

I wish to implement a 2d bit map class in Python. The class would have the following requirements: Allow the creating of arbitrarily sized 2d bitmaps. i.e. to create an 8 x 8 bitmap (8 bytes), something like: bitmap = Bitmap(8,8) provide an API to access the bits in this 2d map as boolean or even integer values, i.e.: if bitmap[1, 2...

Nested Class

What's the best way of accessing the control in the enclosing class from the nested class? Say if I have a dropdown in a form and I have another nested class inside of this class . Now what's the best way to access this dropdownlist from the nested class? ...

Alternative to libraries of static classes

I have a large collection of static 'Utility' classes that contain very generic static methods. For example, I have a CollectionUtility class that has useful methods like: public static void RemoveDuplicates(ICollection collection)... etc With C# 3.0 I've been converting these to extension methods. Now, I've heard some talk that in an...

What is mattr_accessor in a Rails module?

I couldn't really find this in Rails documentation but it seems like 'mattr_accessor' is the Module corollary for 'attr_accessor' (getter & setter) in a normal Ruby class. Eg. in a class class User attr_accessor :name def set_fullname @name = "#{self.first_name} #{self.last_name}" end end Eg. in a module module Authentica...

VB.NET Strong-typed collection

I want to create a collection in VB.NET, but I only want it to accept objects of a certain type. For example, I want to create a class called "FooCollection" that acts like a collection in every way, but only accepts objects of type "Foo". I thought I could do this using generics, using the following syntax: Public Class FooCollect...

Class member organization

What is the best way to sort class members? I'm in conflict with a team member about this. He suggests that we should sort the members alphabetically. I think it's better to organize in a semantic manner: important attributes first, related methods together, etc. What do you think? ...

Unresolved external symbol on static class members

Very simply put: I have a class that consists mostly out of static public members, so I can group similar functions together that still have to be called from other classes/functions. Anyway, I have defined two static unsigned chars in my class' public scope, when I try to modify these values in the same class' constructor, I am gettin...

Is there a way for Ruby accessors to return something other than the set variable?

I want to do some checking in a writer accessor. My first idea was returning a boolean. class MyClass def var=(var) @var = var # some checking return true end end m = MyClass.new retval = (m.var = 'foo') => "foo" Can I set a return value in a writer accessor? If yes, how can I get this value? ...

Structure Vs Class in C#

When you create an instance of a class with the new operator, memory gets allocated on the heap. When you create an instance of a struct with the new operator where does the memory get allocated, on the heap or on the stack ? ...

How do you mark a struct template as friend ?

I have code like this: template <typename T, typename U> struct MyStruct { T aType; U anotherType; }; class IWantToBeFriendsWithMyStruct { friend struct MyStruct; //what is the correct syntax here ? }; What is the correct syntax to give friendship to the template ? ...

Hiding private data members? (C++)

Is there a way to hide private data members of a C++ class away from its users, in the cpp file? I think of the private members as part of the implementation and it seems a little backwards to declare them in the header file. ...

Why do attribute references act like this with Python inheritance?

The following seems strange.. Basically, the somedata attribute seems shared between all the classes that inherited from the_base_class. class the_base_class: somedata = {} somedata['was_false_in_base'] = False class subclassthing(the_base_class): def __init__(self): print self.somedata first = subclassthing(...