Home » Community » Newbie corner » |SOLVED] Vector of object: cast to inherited class
Re: Vector of object: cast to inherited class [message #52364 is a reply to message #52363] |
Sat, 14 September 2019 21:39   |
Novo
Messages: 1430 Registered: December 2006
|
Ultimate Contributor |
|
|
Check how code below works.
A hint: I'm not using a keyword class. I'm using struct instead. This makes code shorter and cleaner.
struct A {
A() {}
virtual ~A() {}
virtual void Hello() const {
Cout() << "Hello from A" << EOL;
}
};
struct B : A {
B() {}
~B() {}
void Hello() const {
Cout() << "Hello from B" << EOL;
}
};
CONSOLE_APP_MAIN
{
Array<A> arrA;
arrA.Create<B>();
arrA.Add(new B);
arrA.Add();
for (const A& a: arrA)
a.Hello();
}
Regards,
Novo
|
|
|
 |
|
|SOLVED] Vector of object: cast to inherited class
By: Xemuth on Fri, 13 September 2019 16:32
|
 |
|
Re: Vector of object: cast to inherited class
By: Novo on Fri, 13 September 2019 21:55
|
 |
|
Re: Vector of object: cast to inherited class
By: Novo on Sat, 14 September 2019 00:29
|
 |
|
Re: Vector of object: cast to inherited class
By: Xemuth on Sat, 14 September 2019 13:41
|
 |
|
Re: Vector of object: cast to inherited class
By: Novo on Sat, 14 September 2019 21:39
|
 |
|
Re: Vector of object: cast to inherited class
By: Novo on Sat, 14 September 2019 21:45
|
 |
|
Re: Vector of object: cast to inherited class
By: Xemuth on Sun, 15 September 2019 12:52
|
 |
|
Re: Vector of object: cast to inherited class
By: Novo on Sun, 15 September 2019 17:31
|
 |
|
Re: Vector of object: cast to inherited class
By: Novo on Sun, 15 September 2019 17:54
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Xemuth on Mon, 16 September 2019 09:35
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Novo on Mon, 16 September 2019 16:29
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Novo on Mon, 16 September 2019 16:31
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Xemuth on Mon, 16 September 2019 16:47
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Novo on Mon, 16 September 2019 17:44
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Xemuth on Mon, 16 September 2019 20:02
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Novo on Mon, 16 September 2019 20:09
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Xemuth on Mon, 16 September 2019 20:25
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Novo on Mon, 16 September 2019 23:47
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Xemuth on Tue, 17 September 2019 09:55
|
 |
|
Re: |SOLVED] Vector of object: cast to inherited class
By: Xemuth on Tue, 17 September 2019 14:11
|
Goto Forum:
Current Time: Tue May 13 18:20:20 CEST 2025
Total time taken to generate the page: 0.04352 seconds
|