up-casting

Does up casting in Java hide the subclass methods and fields?

On the program I'm writing I have a class RestrictedUser and class User that is derived from RestrictedUser. I'm trying to hide the User specific methods by casting to RestrictedUser but when I do the casting the User methods are still available. Also when I run the debugger the type of the variable comes up as User. RestrictedUser rest...

Upcasting pointer reference

I have the following contrived example (coming from real code): template <class T> class Base { public: Base(int a):x(a) {} Base(Base<T> * &other) { } virtual ~Base() {} private: int x; }; template <class T> class Derived:public Base<T>{ public: Derived(int x):Base<T>(x) {} Derived(Derived<T>* &other): Base<T>(other) {} ...

Upcasting without retaining reference to derived type

I have a class called Resource, this is inherited by a class called ResourceMeta I need to upcast ResourceMeta to Resource without it still thinking it is a type of ResourceMeta. When I try to save my object using entity framework, it will complain about mappings not existing, rightly so because it will be trying to save ResourceMeta r...

Cant copy construction be done without creating an explicit function in the pure virtual base class?

My objective is to do a deep copy of a class, but a virtual class is causing trouble. #include<iostream> using namespace std; class Vir//pure virtual class { public: virtual void hi()=0; }; class Handler:public Vir { public: int i; Handler() {} Handler(int val):i(val) {} void hi() {cout<<"Value of i="<<i<<e...