c++ - Downcasting shared_ptr<Base> to shared_ptr<Derived>?

c++ - Downcasting shared_ptr<Base> to shared_ptr<Derived>?

Update: the shared_ptr in this example is like the one in Boost, but it doesn't support shared_polymorphic_downcast(or dynamic_pointer_cast or static_pointer_cast for that matter)! I'm trying to init…


C# foreach behavior with derived classes?

Right now I have a relatively simple class setup: class A{//stuff}class B:A{//more stuff}public List<A> ListOfObjects; What would happen if I do foreach(B i in ListOfObjects) would I get only ob…


Reflection and Operator Overloads in C#

Here's the deal. I've got a program that will load a given assembly, parse through all Types and their Members and compile a TreeView(very similar to old MSDN site) and then build HTML pages for eac…


c# - Inheriting List<T> to implement collections a bad idea?

I once read an article by Imaar Spaanjars on how to build 3 tier applications.(http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1) which has formed the b…


How to downcast a Java object?

I am trying to understand Java's polymorphism, and I have one question about downcasting an object. Let's say for this example I have two subclasses Dog and Cat that inherit from a superclass Animal F…



What's the need to use Upcasting in java?

I've gone through most of the papers in the net, but I'm still not able to understand, why we have to use upcasting. class Animal{public void callme(){System.out.println("In call…


java - Why we can't do List<Parent> mylist=ArrayList<child>();

Why we can't do List<Parent> mylist=ArrayList<child>();…


Downcasting using the 'static_cast' in C++

Consider: class base{base(); virtual void func();}class derived:public base{derived(); void func(); void func_d(); int a;}main{base*b=new base(); size…


c++ - How does one downcast a std::shared_ptr?

Consider: struct SomethingThatsABase{virtual bool IsChildOne() const{return false;}virtual bool IsChildTwo() const{return false;}}; struct ChildOne:public SomethingThatsABase{…


pointers - Go equivalent of a void pointer in C

I've been playing around with Go a little bit making some data structure libraries and I have one big problem. I want the data structure to be able to contain any type, but I don't see any way to do t…




class cast and upcasting downcasting base downcast derived list interface