|
-
Dec 23rd, 2002, 08:42 AM
#1
Thread Starter
Addicted Member
CTypedPtrArray<>
what is the equvalent of
CTypedPtrArray<> in borland c++5?
-
Dec 23rd, 2002, 08:44 AM
#2
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.
-
Dec 23rd, 2002, 08:44 AM
#3
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.
-
Dec 25th, 2002, 03:39 AM
#4
Thread Starter
Addicted Member
-
Dec 25th, 2002, 06:22 AM
#5
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.
-
Dec 26th, 2002, 09:19 PM
#6
Thread Starter
Addicted Member
In the above example.Even If I use pointer it is giving error
CShape* pShape;
pShape=new CLine(............);
-
Dec 27th, 2002, 05:56 AM
#7
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.
-
Dec 27th, 2002, 08:41 AM
#8
Thread Starter
Addicted Member
-
Dec 27th, 2002, 05:49 PM
#9
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.
-
Dec 27th, 2002, 11:18 PM
#10
Thread Starter
Addicted Member
I get the followind errors at pShape=new CLine(............);
1 Type name expected
2 suspicious pointer conversion
-
Dec 28th, 2002, 09:59 AM
#11
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.
-
Dec 30th, 2002, 03:12 AM
#12
Thread Starter
Addicted Member
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 ) ;
-
Dec 30th, 2002, 03:13 AM
#13
Thread Starter
Addicted Member
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 ) ;
-
Dec 30th, 2002, 04:23 PM
#14
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.
-
Dec 31st, 2002, 08:35 PM
#15
Thread Starter
Addicted Member
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?
-
Dec 31st, 2002, 11:07 PM
#16
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.
-
Jan 1st, 2003, 10:01 AM
#17
Thread Starter
Addicted Member
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++;
}
}
-
Jan 1st, 2003, 01:16 PM
#18
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|