Let's say I have the following class hierarchy in C++:
class Base;
class Derived1 : public Base;
class Derived2 : public Base;
class ParamType;
class DerivedParamType1 : public ParamType;
class DerivedParamType2 : public ParamType;
And I want a polymorphic function, func(ParamType), defined in Base to take a parameter of type Deriv...
I have a MustInherit Parent class with two Child classes which Inherit from the Parent.
How can I use (or Cast) Me in a Parent function as the the child type of that instance?
EDIT: My actual goal is to be able to serialize (BinaryFormatter.Serialize(Stream, Object)) either of my child classes. However, "repeating the code" in each ch...
When inheriting classes in C++ I understand members are inherited. But how does one inherit the methods as well?
For example, in the below code, I'd like the method "getValues" to be accessible not through just CPoly, but also by any class that inherits it. So one can call "getValues" on CRect directly.
class CPoly {
private:
in...
Given I have a class with two constructors:
public class TestClass {
ObjectOne o1;
ObjectTwo o2;
public TestClass(ObjectOne o1) {
// ..
}
public TestClass(ObjectTwo o2) {
// ..
}
}
Please assume, that ObjectOne is an interface type, and ObjectTwo implements ObjectOne. What happens, if I call:
...
I have three classes which implement the same protocol, and have the same parent class which doesn't implement the protocol. Normally I would have the protocol as pure virtual functions in the parent class but I couldn't find an Objective-C way to do that.
I want to utilize polymorphism on these subclasses by declaring pure virtual fun...
hello.
I implemented reference counting pointers (called SP in the example) and im having problems with polymorphism which i think i shouldn't have.
In the following code:
SP<BaseClass> foo()
{
// Some logic...
SP<DerivedClass> retPtr = new DerivedClass();
return retPtr;
}
DerivedClass inherits f...
Hi, I'm having a problem with scala generics. While the first function I defined here seems to be perfectly ok, the compiler complains about the second definition with:
error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
def >>[B](a: C[B])(implicit m: Monad[C]): C[B] = {
...
Hi!
I am trying to find some optimal solutions in C++ coding patterns, and this is one of my game engine - related questions.
Take a look at the game object declaration (I removed almost everything, that has no connection with the question).
// Abstract representation of a game object
class Object :
public Entity,
IRenderable...
I noticed there is a dual relation between Writer m and Either e monads. If m is a monoid, then
unit :: () -> m
join :: (m,m) -> m
can be used to form a monad:
return is composition: a -> ((),a) -> (m,a)
join is composition: (m,(m,a)) -> ((m,m),a) -> (m,a)
The dual of () is Void (empty type), the dual of product is coproduct. Every...
Hi!
I'm trying to implement some sort of 'just-for-me' game engine and the problem's plot goes the following way:
Suppose I have some abstract interface for a renderable entity, e.g. IRenderable.
And it's declared the following way:
interface IRenderable {
// (...)
// Suppose that Backend is some abstract backend used
// for re...
What is the difference between Multiple Inheritance and Polymorphism?
In a Book I red a line saying
there is no support for multiple inheritances at class level. This means you can't extend more than one class at a time.
Which is contradicting the concept of Polymorphism, described in the same book as
polymorphism is the process of...
Suppose I have a class Dog that inherits from a class Animal. What is the difference between these two lines of code?
Animal *a = new Dog();
Dog *d = new Dog();
In one, the pointer is for the base class, and in the other, the pointer is for the derived class. But when would this distinction become important? For polymorphism, ...
Hi
Im using the above technologies and have ran into what I presume is a design issue I have made.
I have an Artwork table in my DB and have been able to add art (I now think of these as Digital Products) to a shopping cart + CartLine table fine. The system I have that adds art to galleries and user accounts etc works fine.
Now the cl...
Hi!
Here is the question's plot: suppose I have some abstract classes for objects, let's call it Object. It's definition would include 2D position and dimensions. Let it also have some virtual void Render(Backend& backend) const = 0 method used for rendering.
Now I specialize my inheritance tree and add Rectangle and Ellipse class. Gue...
Hi
I'm having a little scala (version 2.8.0RC1) problem with implicit conversions. Whenever importing more than one implicit conversion the first one gets shadowed. Here is the code where the problem shows up:
// containers
class Maybe[T]
case class Nothing[T]() extends Maybe[T]
case class Just[T](value: T) extends Maybe[T]
case class...
I realize standard C++ only picks functions by argument type, not return type. I.e I can do something like:
void func(int);
void func(double);
but not
double func();
int func();
Where in the former, it's clear, in the latter, it's ambigious. Are there any extensions that lets me tell C++ to pick which function to use also by return...
Possible Duplicate:
Try to describe polymorphism as easy as you can
What is polymorphism?
...
Hi
The MSDN library entry to Enumerable.ElementAt(TSource) Method says
"If the type of source implements
IList, that implementation is used
to obtain the element at the specified
index. Otherwise, this method obtains
the specified element."
Let's say we have following example:
ICollection<int> col = new List<int>...
I have a simple package class which is overloaded so I can output package data simply with cout << packagename. I also have two data types, name which is a string and shipping cost with a double.
protected:
string name;
string address;
double weight;
double shippingcost;
ostream &operator<<( ostream &output, const Pa...
Im trying to make a universal parser using generic type parameters, but i can't grasp the concept 100%
private bool TryParse<T>(XElement element, string attributeName, out T value) where T : struct
{
if (element.Attribute(attributeName) != null && !string.IsNullOrEmpty(element.Attribute(attributeName).Value))
{
...