Todor Atanasov
2014-02-07 21:08:59 UTC
Hi guys, it is me again.
I have entered more deep in C++ and I have reached at a point at which my knowledge is a bit....let say limited:)
This is what I want to do:
To have a CArray (just a array, could be vector, list) with objects, that can be a different classes, but all of them have one method process;
In java this is done with abstract class and then type cast, for example
abstract class Base
{
public abstract void process();
}
class Floor extends Base
{
public void process();
}
and for the loop I can have
List<Floor> objects = new ArrayList<Floor>();
for (int i = 0; i < objects.size(); i++)
{
objects.get(i).process();
}
but how to make that in C++
I can make the two classes with Base having a pure virtual method process.
But how to make the cast of Base to Floor. To me that is impossible because how would the compile knows how to do it.
The purpose of all that is that I need to process objects from different classes and I don't know how to do it.
I have entered more deep in C++ and I have reached at a point at which my knowledge is a bit....let say limited:)
This is what I want to do:
To have a CArray (just a array, could be vector, list) with objects, that can be a different classes, but all of them have one method process;
In java this is done with abstract class and then type cast, for example
abstract class Base
{
public abstract void process();
}
class Floor extends Base
{
public void process();
}
and for the loop I can have
List<Floor> objects = new ArrayList<Floor>();
for (int i = 0; i < objects.size(); i++)
{
objects.get(i).process();
}
but how to make that in C++
I can make the two classes with Base having a pure virtual method process.
But how to make the cast of Base to Floor. To me that is impossible because how would the compile knows how to do it.
The purpose of all that is that I need to process objects from different classes and I don't know how to do it.