Click to See Complete Forum and Search --> : CTypedPtrArray<>
purusingh
Dec 23rd, 2002, 07:42 AM
what is the equvalent of
CTypedPtrArray<> in borland c++5?
CornedBee
Dec 23rd, 2002, 07:44 AM
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.
CornedBee
Dec 23rd, 2002, 07:44 AM
But of course you can use an STL vector.
purusingh
Dec 25th, 2002, 02:39 AM
class TShape:public TStremable
{
private:
..................
.................
pulbic:
virtual void DrawShape(TDC* pDC);
};
class TLine :public TShape
{
public:
virtual void DrawShape(TDC* pDC);
};
class TCircle :public 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());?
CornedBee
Dec 25th, 2002, 05:22 AM
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.
purusingh
Dec 26th, 2002, 08:19 PM
In the above example.Even If I use pointer it is giving error
CShape* pShape;
pShape=new CLine(............);
CornedBee
Dec 27th, 2002, 04:56 AM
What error?
purusingh
Dec 27th, 2002, 07:41 AM
Cast type error
CornedBee
Dec 27th, 2002, 04:49 PM
???
Very strange...
purusingh
Dec 27th, 2002, 10:18 PM
I get the followind errors at pShape=new CLine(............);
1 Type name expected
2 suspicious pointer conversion
CornedBee
Dec 28th, 2002, 08:59 AM
Are you sure pShape is declared correctly and in the right scope?
purusingh
Dec 30th, 2002, 02:12 AM
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 ) ;
purusingh
Dec 30th, 2002, 02:13 AM
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 ) ;
CornedBee
Dec 30th, 2002, 03:23 PM
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.
purusingh
Dec 31st, 2002, 07:35 PM
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?
CornedBee
Dec 31st, 2002, 10:07 PM
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)?
purusingh
Jan 1st, 2003, 09:01 AM
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++;
}
}
CornedBee
Jan 1st, 2003, 12:16 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.