|
Hi
I have 2 base interfaces, IViewBase (which all views will implement) and IPresenterBase (which all presenters will implement):
public interface IViewBase { } public interface IPresenterBase { IViewBase View { get; set; } }
Then i've created a new interface...
Started by Sys on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
You probably want to use generics here:
public interface IViewBase { } public interface IPresenterBase<T> where T : IViewBase { T View { get; set; } }
then:
public interface ILogPresenter : IPresenterBase<ILogView> { } public interface ILogView... .
|
|
Can I force a parent class to call a derived class's version of a function?
class Base(object): attr1 = '' attr2 = '' def virtual(self): pass # doesn't do anything in the parent class def func(self): print "%s, %s" % (self.attr1, self.attr2) self.virtual...
Started by Paul on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
If there is no instance of Derived involved, then there's no suitable self virtual(self): pass def func(self, cb): print....
If you instantiate a Derived (say d = Derived() ), the .virtual that's called by d.func() is Derived.virtual .
|
|
What's the difference between a derived object and a base object in c++,
especially, when there is a virtual function in the class.
Does the derived object maintain additional tables to hold the pointers
to functions?
Started by MainID on
, 12 posts
by 12 people.
Answer Snippets (Read the full thread at stackoverflow):
A derived object can override
a public colon.
derived - is the object the inherits his father's public (and protected) members.
Derived is Base, but Base is not a Derived
base- is the object you are deriving from.
|
Ask your Facebook Friends
|
I want to partially specialize an existing template that I cannot change ( std::tr1::hash ) for a base class and all derived classes. The reason is that I'm using the curiously-recurring template pattern for polymorphism, and the hash function is implemented...
Started by Doug on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at stackoverflow):
Derived, typename boost::enable_if< std::tr1::is_base_of<CRTPBase<Derived>, Derived>.
|
|
I know that the derived class can't access the private members of the base class, so why does the derived class inherit the private members of the base class? Is there any case that it is useful?
Thanks!
Started by skydoor on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The reason is because derived....
An instance of the derived class contains instances by that question.
The derived class doesn't "inherit" the private members of the base class in any way - it can't access them, so it doesn't "inherit" them.
|
|
I have a simple base class and derived class:
class Base { public virtual void Write(int value) { Console.WriteLine("base int: {0}", value); } public virtual void Write(string value) { Console.WriteLine("base string: {0}", value); } } class Derived : ...
Started by Jeff Moser on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Add this....
EDIT II
The below does work, but it's uber hackey, and I don't like it .
I'll verify, but if you override the string overload in your derived class have to rename your derived virtuals to avoid collision.
To the referenced type.
|
|
From an OOP point of view is there any difference between a derived class and an inherited class? Or is it simply terminology?
Started by JL on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
The term derived class is preferred C++ parlance for a class that inherits derives Base Class (Sub Class is a derived class of Base Class) and the Sub Class inherits from Base.
Is called the 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...
Started by Surya on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You need to declare the function in Derived in order to be able to overload it:
class Derived : public Base { template <typename T> void fun (T arg) { Base::fun<T>(arg); } } ;....
Is declared in Base and not in Derived .
|
|
I have a generic class in my project with derived classes.
public class GenericClass <T> : GenericInterface<T> { } public class Test : GenericClass <SomeType> { }
Is there any way to find out if a Type object is derived from the GenericClass...
Started by bernhardrusch on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Try this code
static bool IsSubclassOfRawGeneric(Type generic, Type toCheck) { while (toCheck != typeof(object)) { var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; if (generic == cur) { return true; } toCheck = toCheck.BaseType... .
|
|
There is any way to determine if an object is exactly a class and not a derived one of that?
For instance:
class A : X { } class B : A { }
I can do something like this:
bool isExactlyA(X obj) { return (obj is A) && !(obj is B); }
Of course if there are...
Started by FerranB on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Generalizing snicker's answer:
public....
Control.GetType() == typeof(Label)
More information about the typeof and is operators, as well as the GetType method .
In your specific instance:
bool isExactlyA(X obj) { return obj.GetType() == typeof(A); }
I see.. .
|