Is it possible to define an array`s different layers as different types, classes?
I`m not sure but I think it may be done by templates, but how?
Would you please make me know how to do this or if there is any other existing way.
Thanks in advance.
Printable View
Is it possible to define an array`s different layers as different types, classes?
I`m not sure but I think it may be done by templates, but how?
Would you please make me know how to do this or if there is any other existing way.
Thanks in advance.
What are array layers?
vector is an existing way, if you mean layers as in generic programming, check out the STL at sgi.com
I couldn`t find the exact word, but I remember now : "element"
If an array is defined as theArray[3] ;
theArray[0] , theArray[1] , theArray[2] are the elements of theArray[3] , I think :o
Sorry :o
All I want to do is this:
Suppose:
class CLine {public: void DrawLine() {/*Draw a line*/}; };
class CArc{public: void DrawArc() {/*Draw an arc*/}; };
if an array has two elements Shapes[2]
Define the element Shapes[0] as CLine and Shapes[1] as CArc
How can this be possible? Or firstly, can this be possible? :(
It is called polymorphism, take a look at this tutorial
http://newdata.box.sk/bx/c/
Btw, you should also read the chapters before just to make sure you understand some other important concepts.
Thanks a lot for your replies and interest , Kedaman, and also CornedBee for his interest.
I know polymorphism, because I started learning C++ with the online version of Teach Yourself C++ in 21 Days. :D
I have had the idea to use inheritance also. But to do this I have to create an empty base class that inherits CLine, CArc etc.
But here has been a problem: I have been using Visual Studio .NET Beta 1 and mostly it doesn`t let me access to the members of an object (it usually forgets the mission of the " . " for objects and "->" for pointers to classes. )It`s just a weird. So it has always made me mistaken. I thought that I was doing something wrong, even I did right.
Anyway, I will try polymorphism.
Thank you very much, again.