I've got the following structure:
struct A
{
A();
virtual ~A();
virtual void Foo() =0;
};
struct E;
struct F;
struct B: public A
{
B();
virtual ~B();
virtual void Bar(E*) =0;
virtual void Bar(F*) =0;
};
struct C: public B
{
C();
virtual ~C();
void Bar(E*);
};
struct D: public C
{
...
I have a model
BaseModel
and several subclasses of it
ChildModelA(BaseModel), ChildModelB(BaseModel), ...
using multi-table inheritance. In future I plan to have dozens of subclass models.
All subclasses have some implementation of method
do_something()
How can I call do_somthing from a BaseModel instance?
Almost identica...
I'm using a container UIView to house a UIImageView and do some custom drawing. At this point I'd like to do some drawing on top of my subview. So overriding drawRect: in my container UIView will only draw below the subviews.
Is there a way to overload drawRect: in my subview without subclassing it?
I think method swizzling may be th...
I don't understand what does the overloaded term mean in the context of msdn library's page for MemoryStream Close method (or others like Dispose).
See the page here.
To me, overloaded points out the fact that you are providing a method with the same name but different signature than an existing one AND in the same class.
In this case,...
Suppose I have some code like this:
class Base {
public:
virtual int Foo(int) = 0;
};
class Derived : public Base {
public:
int Foo(int);
virtual double Foo(double) = 0;
};
class Concrete : public Derived {
public:
double Foo(double);
};
If I have a object of type Concrete, why can I not...
public static class StringHelper
{
public static string HyphenAndSpaceReplacer(this string s)
{
string newString = s;
newString.Replace(char.Parse(" ", "_"));
newString.Replace(char.Parse("-", "_"));
return newString;
}
}
Error:
No overload for method 'Parse' takes '2' arguments
No overload for method 'Replace' takes '1...
I'm attempting to make a messaging system in which any class derived from "Messageable" can receive messages based on how the function handleMessage() is overloaded. For example:
class Messageable
{
public:
void takeMessage(Message& message)
{
this->dispatchMessage(message);
}
prot...
Using LINQ to Entities, I have the following code:
public Foo GetFooByID(int id)
{
return _db.Foo.First(m => m.ID == id);
}
public Bar GetBarByID(int id)
{
return _db.Bar.First(m => m.ID == id);
}
Is there a way to refactor this using generics?
...
I'd like to add a generic type method DoSomething<T>, but for backwards compatibility, I want it to simply pass the type parameter for the generic type from an existing method with the same name.
public void DoSomething<T>(Data data)
{
//do something with Data, it depends on the type of T
}
public void DoSomething(Data data, Type d...
Hello,
For the following code why does it print A, B? I would expect it to print B, B.
Also, does the method call performed by the JVM is evaluated dynamically or statically?
public class Main {
class A {
}
class B extends A {
}
public void call(A a) {
System.out.println("I'm A");
}
public void...
Question edited to better reflect my needs.
Take the following example:
class Base
{
public $Text = null;
public function __construct()
{
$this->Text = new Base_Text();
}
}
class Base_Text extends Base
{
public $Is = null;
public function __construct()
{
$this->Is = new Base_Text_Is();
...
In a PHP web application I'm working on, I see functions defined in two possible ways.
Approach 1:
function myfunc($arg1, $arg2, $arg3)
Approach 2:
// where $array_params has the structure array('arg1'=>$val1, 'arg2'=>$val2, 'arg3'=>$val3)
function myfunc($array_params)
When should I use one approach over another? It seems that i...
I am bubbling events in my application and so therefore using the bubble events method. As this method handles all sorts of bubbled events their is a switch or if statement within it to determine what sort of event we're dealing with. I was wondering if I could get around this by creating different versions of the event args class. So...
Suppose we have:
public class FooBase
{
public void Write(byte value)
{
//something
}
public void Write(int value)
{
//something
}
}
public class Foo : FooBase
{
public void Write(decimal value)
{
//something
}
}
than this:
var writer = new Foo();
writer.W...
I am trying to implement an audit trail into my application, but because of some requirements I am unable to use any existing gems or plugins.
I would like to divert any normal attempt to update a model to a custom method that saves all the updates in another separate Table (called Updates).
The application then uses the update table t...
Ok, I'm trying to do the following:
protected bool ValidAdvert(Base item)
{
throw ThisIsAnAbstractClassException();
}
protected bool ValidAdvert(Derived1 item)
{
return ADerived1SpecificPredicate;
}
protected bool ValidAdvert(Derived2 item)
{
...
Hello
I have a base-class called Element. Some other classes (like Label and Image) both extend this class.
I now have a dispatching class having the following methods:
public class Dispatcher {
public static AbstractPropertyEditor<Label> createEditor(Label e) {
...
}
public static AbstractPropertyEditor<Element> crea...
hello,
as far as my knowledge, objective-C does not support method overloading.What can be the alternative for this in Objective-C? or should i always use different method name?
...
In other words, what are the precise rules for how the Java compiler determines which overloaded method to choose to execute? I've spent a good amount of time googling and I think I'm not using the right search keywords.
public class C1 extends C2 {}
public class C2 extends C3 {}
public class C3 {}
public class Test {
public st...
Why does the following program throw an exception?
public class MainClass{
public static void main(String[] argv){
callMethod(2);
}
public static void callMethod(Integer... i){
System.out.println("Wrapper");
}
public static void callMethod(int... i){
System.out.println("Primitive");
}
}
The method cal...