Edit: It turns out I missed something obvious, but I'm going to leave the question open in case someone else makes the same obvious mistake. Thanks to those who pointed it out See bottom for explanation.
Is it possible to have a non-public set on a property that is overriding an interface property?
Perhaps I'm having a stupid moment, b...
First time on StackOverflow, so please be tolerant.
In the following example (apologies for the length) I have tried to isolate some unexpected behaviour I've encountered when using nested classes within a class that privately inherits from another. I've often seen statements to the effect that there is nothing special about a nested cl...
I'm writing different implementations of immutable binary trees in C#, and I wanted my trees to inherit some common methods from a base class.
Unfortunately, classes which derive from the base class are abysmally slow. Non-derived classes perform adequately. Here are two nearly identical implementations of an AVL tree to demonstrate:
...
Hi all,
I have
class A
{}
class B : A
{}
I also have a method that expects a List parameter
void AMethod(List<A> parameter)
{}
Why can't I
List<B> bs = new List<B>();
AMethod(bs);
And secondly what is the most elegant way to make this work?
regards
...
I'm writing some examples of hash functions for hash_map. If I use a hash_map defined by my compiler, I need to define Comparer in Hasher. I know that it's better to use tr1::unordered_map but in my application it's important to set minimum number of buckets rather big and define mean bucket_size - a condition to grow.
So I would like t...
Hi,
I have created a simple API to convert arbitrary objects into human-readable strings. Think of it as a generalized String.valueOf() functionality.
The API achieves this by selecting an
public interface ObjectFormatter {
public String format(Object object);
public Class getObjectClass();
public boolean offe...
I am trying to get a Javascript object to use the "this" assignments of another objects' constructor, as well as assume all that objects' prototype functions. Here's an example of what I'm attempting to accomplish:
/* The base - contains assignments to 'this', and prototype functions
*/
function ObjX(a,b) {
this.$a = a,
...
I have an object for a subclass who is of it's superclass type. There is a overridden function in subclass which gets executed when called using the object. How to call the parent's function using the same object? Is there any way to achieve this?
package supercall;
public class Main {
public static void main(String[] args) {
...
Hello everyone,
It is mentioned in C++ FAQ site -- "larger derived class objects get sliced when passed by value as a base class object", what does slicing mean? Any sample to demonstrate?
http://www.parashift.com/c++-faq-lite/value-vs-ref-semantics.html#faq-31.8
I am using VSTS 2008 + native C++ as my development environment.
thanks...
Why does the following produce a compiler error:
public interface OwnSession : ISession { }
[...]
OwnSession s = SessionFactory.OpenSession(); // compiler error (in german unfortunately)
[...]
"SessionFactory" returns a "ISession" on "OpenSession()" (NHibernate)
...
Given a base class with the following interface:
public class Base
{
public virtual IEnumerable<string> GetListOfStuff()
{
yield return "First";
yield return "Second";
yield return "Third";
}
}
I want to make a derived class that overrides the method, and adds its own stuff, like so:
public class D...
Hello there,
I'm experimenting with C# 4.0's dynamic object model.
I've created an abstract class named "Block" that inherits from DynamicObject. It overrides TryGetMember and TrySetMember.
Furthermore I've created a usable class named "Brush" that inherits from "Block". I want it to be usable dynamically.
But when I create a dyna...
I want to specifically invoke the base class method; what's the most concise way to do this? For example:
class Base
{
public:
bool operator != (Base&);
};
class Child : public Base
{
public:
bool operator != (Child& child_)
{
if(Base::operator!=(child_)) // Is there a more concise syntax than this?
return true;
/...
Say you have the following in a schema:
<xsd:complexType name="shape"/>
<xsd:complexType name="circle">
<xsd:complexContent>
<xsd:extension base="shape">
<xsd:attribute name="radius" type="xsd:double"/>
</xsd:extension>
</xsd:complexContent>
</xsd:c...
class Base
{
public:
int base_int;
};
class Derived : public Base
{
public:
int derived_int
};
Base* basepointer = new Derived();
basepointer-> //Access derived_int here, is it possible? If so, then how?
...
when accessing foo() of "base" using derived class's object.
#include <iostream>
class base
{
public:
void foo()
{
std::cout<<"\nHello from foo\n";
}
};
class derived : public base
{
public:
void foo(int k)
{
std::cout<<"\nHello from foo with value = "<<k<<"\n";
}
};
int main(...
Hi,
I have a simple code fragment in JS working with prototype inheritance.
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
//the following code block has a alternate version
var mammal = {
color: "brown",
getColor: function() {
return this.color;
}
}
var myCat = object(mammal)...
In Douglas Crockford's JavaScript: The Good Parts he recommends that we use functional inheritance. Here's an example:
var mammal = function(spec, my) {
var that = {};
my = my || {};
// Protected
my.clearThroat = function() {
return "Ahem";
};
that.getName = function() {
return spec.name;
...
Hi,
In the .net framework, there's a generic IEnumerable<T> interface which inherits from the not-generic IEnumerable, and they both have a GetEnumerator() method. The only differents between these two GetEnumerator() is the return type.
Now I have a similar design, but when I compile the code, the compiler said:
MyInterface<T>.GetIte...
I'm planning to have collection of items stored in a TCollection.
Each item will derive from TBaseItem which in turn derives from TCollectionItem,
With this in mind the Collection will return TBaseItem when an item is requested.
Now each TBaseItem will have a Calculate function, in the the TBaseItem this will just return an internal v...