inheritance

Problems trying to override methods in Objective-C (iPhone)

Hello there, this my problem i have a class X that inherits UITableViewController class and a class Y that inherits the X class, when i try to override a method in the Y class the method in the X class is invoked... and i can't find references to understand what's happening... can anyone help me? Thanks in advance! Code! mluListBuilde...

C# interfaces and type masquerading

My subclasses don't appear to be able to masquerade as the base class when satisfying interface requirements. For example: class MyBaseClass {} class MySubClass : MyBaseClass {} interface MyInterface { MyBaseClass someFunction(); } class MyImplementation : MyInterface { public MySubClass someFunction() { return null; } } Ge...

Setting private property value in constructor of inherited class

I've got a base class from an outside library that I can't modify - here's the relevant piece: public class BaseClass { List<string> _values; public Values { get { return _values; } } } I am inheriting the BaseClass, and I want to set _values to a class that inherits from List(T) in the constructor: public InheritingClass :...

Java classes inheritance

Here, it says that: This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document the state and behavior that each superclass defines, since that code ...

Allow field in a child class to be of a type descended from the type of the field in the parent class

I have the following setup (simplified, obviously): An abstract class, with an A object and an abstract method abstract public class X { protected A myA; abstract public int MethodForX(); } Two inheriting classes, each of which override the method. However instead of using an A object they use a B and C object, each of which ...

Function template specialization in derived class.

Hello all, I've a base class with a function template. I derive from base class and try to have a specialization for the function template in derived class I did something like this. class Base { .. template <typename T> fun (T arg) { ... } }; class Derived : public Base { ... } ; template <> Derived::fun(int arg); and in .cpp ...

When overriding a virtual member function, why does the overriding function always become virtual?

Hi! When I write like this: class A { public: virtual void foo() = 0; } class B { public: void foo() {} } ...B::foo() becomes virtual as well. What is the rationale behind this? I would expect it to behave like the final keyword in Java. Add: I know that works like this and how a vtable works :) The question is, why C++ st...

abstract classes and interfaces best practices in java

So you've got an interface and an abstract class that implements a subset of the methods in the interface. You've also got some classes that inherit the abstract class and give implementations of the methods the abstract class doesn't give. So what's the best practice here? I'm talking about issues like: 1) Should the abstract class im...

android 101 - listview inheritance question

I have a ListView in my extended ListActivity class. And then I have the following code to detect my click on the list protected void onListItemClick(ListView l, View v, int position, long id) { Log.i("", ""+l.getSelectedItem().toString()); } I want to get the data string associated to my click. When I run the code, I get an er...

Generic type inference with interface inheritance (co(ntra)-variance?) in C# 3

I have the following two generic types: interface IRange<T> where T : IComparable<T> interface IRange<T, TData> : IRange<T> where T : IComparable<T> ^---------^ | +- note: inherits from IRange<T> Now I want to define an extension methods for col...

C++ Destructor Behavior

I had a question about C++ destructor behavior, more out of curiosity than anything else. I have the following classes: Base.h class BaseB; class BaseA { public: virtual int MethodA(BaseB *param1) = 0; }; class BaseB { }; Imp.h #include "Base.h" #include <string> class BImp; class AImp : public BaseA { public: ...

C++ design question

Suppose I have a class Base which has a member variable A* my_hash. I also have class Extended which inherits from class Base. I also have a class B which extends A. class Base{ Base(): my_hash(new A) {} //methods which use my_hash protected: A* my_hash; }; class Extended:public Base{ //methods which use my_hash from A //I can...

Java Inheritance

Hello, I have a question regarding inheritance in Java. If I have this base class class Parent { private String lastName; public Parent() { lastName = "Unassigned"; } public String getLastName( ) { return lastName; } public void setLastName(String name) { lastName = name; } } And...

Polymorphism and inheritance of static members in C++

Hello, I need to keep a list(vector) of children for every class, and I've got a tricky problem: class A { protected: int a; static vector<A*> children; public: A(int a): a(a) {;}; virtual void AddToChildren(A* obj); virtual void ShowChildren(); virtual void Show(); }; class B: public A { protected: int...

Base Class Awareness of Property Changes in Derived Classes

I was wondering if anyone had a possible solution to the following problem... I have a base class that a series of derived classes will inherit from. The base class cares about whether properties on the derived class have changed. This is to set up an "IsDirty" approach for a data transfer object. The traditional approach would be to...

Inheriting Custom Operators in Python?

If I have class A that defines __cmp__, and class B that extends class A, it seems like I have to redefine __cmp__ in class B. Is this correct? Is there a better workaround than implementing a method "cmp" in class A and calling it from the separate implementations of __cmp__ in class A and class B? Thanks, -aj UPDATE: The issue s...

Fluent NHibernate table per subclass inheritance mapping

I'm new to NHibernate and Fluent NHibernate. I'm wondering how to properly use Fluent NHibernate with the "table per subclass" mapping strategy. This is an example of what I'm after. More specifically though, I need a way to break the subclass mappings into separate files. Also, when adding records, I need NHibernate to first insert in...

Why access to filed and method differs in inherited class in Java?

class BaseClass { protected int filed = 1; public void method() { System.out.println("+ BaseClass method"); } } class DerivedClass extends BaseClass { private int filed = 2; public void method() { System.out.println("+ DerivedClass method"); } public void accessFiled() { System.out.p...

Upcasting pointer reference

I have the following contrived example (coming from real code): template <class T> class Base { public: Base(int a):x(a) {} Base(Base<T> * &other) { } virtual ~Base() {} private: int x; }; template <class T> class Derived:public Base<T>{ public: Derived(int x):Base<T>(x) {} Derived(Derived<T>* &other): Base<T>(other) {} ...

C++: When is it approperiate to use multiple inheritance (when is is inapropriate and used)

Possible Duplicate: A use for multiple inheritance ? How is multiple inheritance really a useful construct in C++. Why use it? What are examples of where it can solve problems that can not be solved in some other clean way? What are some examples of how to use it in a useful way? How is it misused? What are the problems wi...