Results 1 to 18 of 18

Thread: CTypedPtrArray<>

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163

    CTypedPtrArray<>

    what is the equvalent of
    CTypedPtrArray<> in borland c++5?
    Purushottam

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    CTypedPtrArray is something very specific to the MFC. Actually it's something very stupid which was added to keep compatibility with older apps but at the same time take advantage of the "new" templates feature that was added to C++ after the original MFC came out, while at the same time writing as little code as possible.

    I don't think you will find a direct equivalent in the OWL.
    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
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But of course you can use an STL vector.
    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    class TShapeublic TStremable
    {
    private:
    ..................
    .................
    pulbic:
    virtual void DrawShape(TDC* pDC);
    };

    class TLine ublic TShape
    {
    public:
    virtual void DrawShape(TDC* pDC);

    };

    class TCircle ublic TShape
    {
    public:
    virtual void DrawShape(TDC* pDC);

    };

    typedef TArray<TShape> TShapes;
    typedef TArrayIterator<TShape> TShapeIterator;


    now using this
    how to draw the corosponding shape(DrawShape());?
    Purushottam

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You must make the array of type TShape* or TShape& in order to make polymorphism possible, else you can't add shape-derived classes to the array.
    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    In the above example.Even If I use pointer it is giving error

    CShape* pShape;

    pShape=new CLine(............);
    Purushottam

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What error?
    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.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    Cast type error
    Purushottam

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    ???

    Very strange...
    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.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    I get the followind errors at pShape=new CLine(............);
    1 Type name expected
    2 suspicious pointer conversion
    Purushottam

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Are you sure pShape is declared correctly and in the right scope?
    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.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    Thank U very much from helping me.

    it is working now that I add a containr constructor.But I don't now why we need a container constructor in base class(CShape)?

    And why do we need upper and lower and delta?when it can grow and shrink dynamically in the following?

    TArrayAsVector( int upper, int lower = 0, int delta = 0 ) ;
    Purushottam

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    Thank U very much from helping me.

    it is working now that I add a containr constructor.But I don't know why we need a container constructor in base class(CShape)?

    And why do we need upper and lower and delta?when it can grow and shrink dynamically in the following?

    TArrayAsVector( int upper, int lower = 0, int delta = 0 ) ;
    Purushottam

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Makes it more efficient and generic. You can have a from-to array like in VB and you can specify a large delta when you notice it would help your app (e.g. if you always add several elements in short succession). Delta is how much additional memory this thing allocates when it gets too small.
    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.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    Thanks.

    I think form-to-array doesn't grow.It is just to specify the number of item in it and the index is transformed.isn't it?
    Can i give the three parameter TArrayAsVector(0,0,0)?

    Now I have done

    typedef TArray<CShape*> CShapes;
    typedef TArrayIterator<CShape*> CShapesIterator;

    CShapes m_shapes=new CShapes(5,0,5);



    void CMyWindow::OpenFile()
    {
    ifstream is("c:\\abc.dot");

    if (!is)
    MessageBox("Unable to open file", "File Error", MB_OK | MB_ICONEXCLAMATION);
    else {
    CMyApp* app=(CMyApp*)GetApplication();

    app->m_shapes->Flush();
    unsigned numPoints;
    is >> numPoints;

    while (numPoints--)
    {
    CShape point;
    is >> point;
    app->m_shapes->Add(point);
    }
    }

    Invalidate();

    }

    it gives erron on
    is>>point
    what is wrong with it?
    Purushottam

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Does CShape have an overloaded >> operator? Is it even valid to create a simple CShape object (from an OOP design point of view CShape should be abstract, thus the line
    CShape point;
    should be invalid)?
    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.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Posts
    163
    No I have no done like that.But I hope it is saing to a file.
    This code is giving no error.

    void CMyWindow::SaveFile()
    {
    ofstream os("c:\\abc.dot");

    if (!os)
    MessageBox("Unable to open file", "File Error", MB_OK | MB_ICONEXCLAMATION);
    else
    {
    CMyApp* app=(CMyApp*)GetApplication();
    os << app->m_shapes->GetItemsInContainer();

    CShapesIterator i(*app->m_shapes);

    while (i)
    os<<i++;

    }
    }
    Purushottam

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This doesn't mean anything. Just because a class has an overloaded << operator (Has it? Or does the iterator have one? Or does the iterator have an implicit conversion to some pointer type than can be inserted into the stream?) it doesn't mean it also has an overloaded >> operator.

    And CShape is CShape. Simple value types allow no polymorphism. You have to think of a different method of serializing your objects.
    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.

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