derived-class

Reliable/easy way to replace Windows.Forms control with a derived control?

I didn't follow my own best practices (use only derived controls), and I dragged a regular Windows Forms control to my form, wired it up and used it on my form ;-( Now I need to change the control to a derived control (derived from the same control), preserving all the settings from the designer. Is there a reliable/easy way to do this...

How to access derived class members from an interface?

I have three classes; Stamp, Letter and Parcel that implement an interface IProduct and they also have some of their own functionality. public interface IProduct { string Name { get; } int Quantity { get; set; } float Amount { get; } } public class Stamp : IProduct { public string Name { get { return "Stamp"; } } ...

Do derived classes inherit differently?

System.Web.UI.WebControls.UI.TableHeaderCell derives from System.Web.UI.WebControls.UI.TableCell So a method with the signature foo(TableCell tc){} Will accept instances of TableHeaderCell. However if i create two new classes and derive one from TableCell and the other from TableHeaderCell then my new TableHeaderCell class will ob...

c++ template casting with derived classes

#include <vector> struct A {int a;}; struct B : public A {char b;}; int main() { B b; typedef std::pair<A*, A*> MyPair; std::vector<MyPair> v; v.push_back(std::make_pair(&b, &b)); //compiler error should be here(pair<B*,B*>) return 0; } I don't understand why this compiles (, maybe somebody may kindly provide detailed expla...

How to force a derived class to include certain properties with default value

I have a class structure for a role playing game which looks like this... public abstract class Item { public abstract string Name { get; set; } } public abstract class Armor : Item { public override string Name { get; set; } } public class Helmet : Armor { public override string Name { get; set; } } Basically, I am trying ...

serializable to derived classes

Is there an easy way to enforce a derived class must be serialiable? Suppose I define a interface that needs the derived classes to be serializable. According to this post, I cannot just specify the serializable attribute in the interface, because derived classes don't need to respect that. I believe I could have the interface inherit ...

C++ Access derived class member from base class pointer

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? ...

C# new class with only single property : derive from base or encapsulate into new ?

I've tried to be descriptive :) It's rather programming-style problem than coding problem in itself. Let's suppose we have : A: public class MyDict { public Dictionary<int,string> dict; // do custom-serialization of "dict" public void SaveToFile(...); // customized deserialization of "dict" public void LoadFr...

Objective C, how to query if an object is of a certain class

I am deriving from TableViewCell. When i query the table view about an index path it returns a UITableViewCell. How do i find if this object is one of my custom type "CustomCell"? ...

UiElement based on another class

I placed a control into a grid. let's say the control is derived from public class 'ButBase' which is derived in its turn from System.Windows.Controls.Button. The code normally compiles and app works just fine. But there's something really annoying. When you try to switch to xaml-design tab it will say 'The document root element is not ...

Passing Derived Class Instances as void* to Generic Callbacks in C++

This is a bit of an involved problem, so I'll do the best I can to explain what's going on. If I miss something, please tell me so I can clarify. We have a callback system where on one side a module or application provides a "Service" and clients can perform actions with this Service (A very rudimentary IPC, basically). For future refer...

Why can I derived from a templated/generic class based on that type in C# / C++

Title probably doesn't make a lot of sense, so I'll start with some code: class Foo : public std::vector<Foo> { }; ... Foo f; f.push_back( Foo() ); Why is this allowed by the compiler? My brain is melting at this stage, so can anyone explain whether there are any reasons you would want to do this? Unfortunately I've just seen a sim...

Limited options for accessing events in derived classes?

Im refactoring a class, and moving sections into a base class. I have a few events similar to public event EventHandler GridBinding; Which are now in the base class, but i am finding i cannot now check to see if the event is null in my derived class. Doing so gives me the error: The event 'xyz.GridBinding' can only appear on t...

Calling base class constructor

In the program below, is the line Derived(double y): Base(), y_(y) correct/allowed? That is, does it follow ANSI rules? #include <iostream> class Base { public: Base(): x_(0) { std::cout << "Base default constructor called" << std::endl; } Base(int x): x_(x) { std::cout << "Base constructor called with x = " << x...

How do I create custom Controls for my VS2005 toolbox?

Ok, this question might more about design theory. I have successfully created controls that show up in my toolbox, so I'm pretty sure I have the process right. Also, my "AutoToolboxPopulate" is set to true, so things are showing up as I create them. My question is this: I'm sub-classing a native Control for specialized use. When I de...

How does versioning work when using Boost Serialization for Derived Classes?

When a Client serializes the following data: InternationalStudent student; student.id("Client ID"); student.firstName("Client First Name"); student.country("Client Country"); the Server receives the following: ID = "Client ID" Country = "Client First Name" instead of the following: ID = "Client ID" Country = "Client Country" The...

polymorphism, inheritance in c# - base class calling overridden method?

This code doesn't work, but hopefully you'll get what I'm trying to achieve here. I've got a Money class, which I've taken from http://www.noticeablydifferent.com/CodeSamples/Money.aspx, and extended it a little to include currency conversion. The implementation for the actual conversion rate could be different in each project, so I d...

WCF- "The underlying connection was closed: The connection was closed unexpectedly"

Hi there. I'm recieving that wonderfuly ambiguous error message when using one of my webmethods on my WCF webservice. As that error message doesn't provide any explanation whatsoever allow me to post my theory. I believe it may have something to do with the return type I'm using I have a Types DLL which is refrenced in both the webser...

Why is 'virtual' optional for overridden methods in derived classes?

When a method is declared as virtual in a class, its overrides in derived classes are automatically considered virtual as well, and the C++ language makes this keyword virtual optional in this case: class Base { virtual void f(); }; class Derived : public Base { void f(); // 'virtual' is optional but implied. }; My question is...

POCO inherited type could not pass addObject method

Hi all I am using a POCO class name "Company" generate from the T4 POCO code generator to create a derived class - name "CompanyBO" by "public class CompanyBO:Company", but when i call addObject method: public void Delete(T entity) { CustomerWebPortalEntities entities = new CustomerWebPortalEntities(); ...