Upcasting permits an object of a subclass type to be treated as an object of any superclass type.
Questions tagged [upcasting]
244 questions
0
votes
1 answer
Upcasting in C++ : cannot convert child class pointer to parent class pointer
I have a problem with my program. I made a Graph class in C++, and now I want to sort it topologically. The thing is, my topological sort accepts any DirectedGraph, but when I want to give it a child (AdjacencyListDirectedUnweightedGraph for…

Fedou
- 1
- 2
0
votes
1 answer
Java: Does an upcasted object use the overrided methods of the super or subclass?
Ok, so my basic class hierarchy is as follows:
abstract public class Shape ---> public class Circle.
Here is the code for the shape and circle. No need to read, just here for reference; mostly getters and setters anyway. I would recommend looking…

louie mcconnell
- 701
- 3
- 7
- 20
0
votes
0 answers
Raising SIGABRT on destructor call
I have the current class
class VectorVectorRow : public virtual RowFormat {
private:
std::vector>* mat;
int r_pos;
public:
VectorVectorRow (std::vector>* r,int pos) : mat{r}, r_pos{pos} {};
…

jackb
- 695
- 8
- 26
0
votes
0 answers
Call derived class method when upcasted
Right now I have a hierarchy as follows (-> means parent of )
LSystem -> DLSystem -> Tree -> MonopodialTree
-> TernaryTree
And I have a function substitute which is defined in LSystem as follows and given a minimal…

Jose Javier Gonzalez Ortiz
- 468
- 1
- 5
- 16
0
votes
2 answers
Why won't upcast to concrete type of another common interface
Why can't you upcast to a different concrete type of another common interface. I've created this example in linqpad. Now I can understand if you had different properties between the two classes that an up cast would fail because it couldn't…

johnny 5
- 19,893
- 50
- 121
- 195
0
votes
1 answer
Java static and dynamic types
A downcast can change the dynamic type of an object.
Why is this statement false? Is that because, there aren't static and dynamic types in Java?
Moreover, what is the static type and dynamic types of an object?

codemonkey
- 331
- 1
- 4
- 16
0
votes
1 answer
Up-casting template argument types
Why does Java not support automatic up-casting for template argument types?
For example, the following class will not compile unless the newly created Derived instance will be manually casted to a Base instance:
public class Example implements…

Tim
- 5,521
- 8
- 36
- 69
0
votes
0 answers
Calling private function by upcasting
In the follwing class, I upcast a derived object to a base pointer. I'm then able to call the 'private' member function of derived from the main. How is this possible? My hunch is that whether a function can be called(i.e access) is based on the…

Pranav Kapoor
- 1,171
- 3
- 13
- 32
0
votes
1 answer
Java Upcasting Nested Type Parameter
Given the Java code below, I want to know why upcasting Foo to Foo

user1413793
- 9,057
- 7
- 30
- 42
0
votes
3 answers
C# Upcasting / Polymorphism Issue
I believe this question is fairly basic but I am having trouble finding an answer to this question. In C# let's say I have 3 classes: A, B, C
B derives from A
C derives from B
Now, if I wanted a list or array of objects of type class A but wanted…

Brad Mash
- 69
- 6
0
votes
2 answers
dynamically upcast arrays of identically typed instances
Given this linqpad code:
interface I {}
public class A : I {}
public class B : A {}
void Main()
{
var i = new List(new I[] { new A(), new B(), new A(), new B() });
i.GroupBy(_ => _.GetType()).Select(_ => _.ToArray()).Dump();
}
What is…

Jim
- 14,952
- 15
- 80
- 167
0
votes
3 answers
When does C not need the address-of operator?
In C are there any times other than for arrays that the address-of operator is not needed? For example, I know this code needs the address of operator:
typedef struct foo_t {
int bar;
} foo_t;
void foo_init(foo_t *f) { f->bar = 123; }
... {
…

Kristopher Ives
- 5,838
- 7
- 42
- 67
0
votes
2 answers
Confusion about upcasting and overloaded methods
Let's say, we have these two classes and one main method:
public class Super {
public void f(double d){
System.out.println("Super: f(double d)");
}
public void f(int i){
System.out.println("Super: f(int i)");
…

Christopher
- 2,005
- 3
- 24
- 50
0
votes
5 answers
Object of child class cannot call its own methods
If c is a ChildClass object then why can't it call methods of ChildClass?
Like:
ParentClass c=new ChildClass(); //Here ChildClass extends ParentClass
In particular:
Object s=new StringBuffer();
Here s is object of StringBuffer, but s.append(null)…

Malwinder Singh
- 6,644
- 14
- 65
- 103
0
votes
2 answers
C# implicit cast from base class to extended (System.Reflection.Assembly)
I've been working the project mentioned c-sharp-compilerresults-generateinmemory.
I've been writing a lot of code to get my "class discovery" implemented. It works cool, but I realized it would be a lot more efficient if I implemented everything…

Aage Torleif
- 1,907
- 1
- 20
- 37