Suppose I have a base class B, and a derived class D. I wish to have a method foo() within my base class that returns a new object of whatever type the instance is. So, for example, if I call B.foo() it returns an object of type B, while if I call D.foo() it returns an object of type D; meanwhile, the implementation resides solely in t...
Firstly I'm extending an existing class structure and cannot alter the original, with that caveat:
I would like to do this:
class a
{
int val;
... // usual constructor, etc...
public int displayAlteredValue(int inp)
{
return (val*inp);
}
}
class b extends a
{
... // usual constructor, etc...
public in disp...
In a C# program, I have an abstract base class with a static "Create" method. The Create method is used to create an instance of the class and store it locally for later use. Since the base class is abstract, implementation objects will always derive from it.
I want to be able to derive an object from the base class, call the static C...
In C#, I have base class Product and derived class Widget.
Product contains a static method MyMethod().
I want to call static method Product.MyMethod() from static method Widget.MyMethod().
I can't use the base keyword, because that only works with instance methods.
I can call Product.MyMethod() explicitly, but if I later change Widg...
I have a base class that does calculations on image sizes. I'm deriving a class from that and have predefined image sizes that will be used in my code. While what I have works, I have a strong feeling that I'm not doing it properly.
Ideally, I'd like to just pass DerviedClass.PreviewSize as the parameter to GetWidth without having to cr...
Is it possible to assign a base class object to a derived class reference with an explicit typecast in C#?.
I have tried it and it creates a run-time error.
...
My problem here is that I would like to pass an object to a derived class, but it must be done before the base class constructor, since the base class will immediately call the derived class's Start() method that uses the object.
Here's an excerpt from the base class, (renamed from BarcodeScanner for convenience).
public abstract class...
Hello,
the problem i encounter seems pretty obvious but i cannot find the flaw on my code, so i guess it might be too obvious for me to see the problem...
I'm building a notification framework and for that i'm serializing and deserializing a basic class, from wich all the classes i want to send will derive.
the problem is that the cod...
Theoretically you can derive from a Form but is it something you should not do? I intuitively think so but I've never heard of any rule like this.
Edit: of course I meant some conrete class that already derives from Form. For example if I've got class MyForm : Form, the question is can i derive from MyForm?
...
I have a parameterized hibernate dao that performs basic crud operations, and when parameterized is used as a delegate to fulfil basic crud operations for a given dao.
public class HibernateDao <T, ID extends Serializable> implements GenericDao<T, ID>
I want to be able to derive Class from T at runtime to create criteria queries in Hi...
Ok, so I have a base class which declares the event StatusTextChanged. My child class, of course cannot directly raise this event.
So I wind up with something like this (for simplicity sake):
Public MustInherit Class FooBase
Public Event StatusTextChanged(ByVal StatusText As String)
Protected Sub RaiseStatusTextChangedEvent(By...
I have a basic class that derived subclasses inherit from, it carries the basic functions that should be the same across all derived classes:
class Basic {
public:
Run() {
int input = something->getsomething();
switch(input)
{
/* Basic functionality */
case 1:
doA();
break;
case 2:
...
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 in the CRTP base class. If I only want to partially specialize for a the CRTP base...
Hi,
Is it possible to access a base class function which has the same signature as that of a derived class function using a derived class object?. here's a sample of what I'm stating below..
class base1 {
public:
void test()
{cout<<"base1"<<endl;};
};
class der1 : public base1 {
public:
void test()
{cout<<"der1"<<endl;...
Why I can't access base class A's a member in class B initialization list?
class A
{
public:
explicit A(int a1):a(a1)
{
}
explicit A()
{
}
public:
int a;
public:
virtual int GetA()
{
return a;
}
};
class B : public A
...
I have a base class where I derive several classes. I have another class that uses all those derived classes in a different way. However, I want to call the Update() method (inherited from the base class) on each derived class. Is there an easy way to do this, or do I have to do something like:
dim a As Derived1
a.Update
dim b As Deriv...
I have an abstract base class for audit properties. For brevity say it has one property
Public MustInherit Class AbstractAuditableEntity
...
Public Property CreatedTime() As DateTimeOffset
...
End Class
And then my auditable domain objects inherit from this class
Public Class Source
Inherits AbstractAuditableEntity
...
using System.ComponentModel;
using System.IO;
using System.Xml.Serialization;
namespace SerializerTest {
static class Program {
static void Main() {
using (TextWriter textWriter = new StreamWriter("data.xml")) {
Data data = new Data();
new XmlSerializer(typeof(Data)).Serialize(textWriter, data);
textW...
I have to do this for a basic C++ lecture at my university, so just to be clear: i would have used the STL if i was allowed to.
The Problem: I have a class named "shape3d" from which i derived the classes "cube" and "sphere". Now i have to implement "shape3d_stack", which is meant be able of holding objects of the types "cube" and "sphe...
I've tried to understand some of the posts of similar, but don't quite understand their purposes and thought I'd explain my own...
I have a class -- fully defined with code with properties, and methods. Many methods are virtual to be overriden by further derived class. So, I have something like the following
Class_Main
-- Class_A ...