Results 1 to 6 of 6

Thread: Defining array elements as different types?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46

    Post Defining array elements as different types?

    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.
    Last edited by might; Mar 3rd, 2002 at 05:15 AM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What are array layers?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    vector is an existing way, if you mean layers as in generic programming, check out the STL at sgi.com
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    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
    Sorry

    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?

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    46
    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.
    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.
    Last edited by might; Mar 3rd, 2002 at 08:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width