|
-
May 13th, 2002, 04:05 AM
#1
Thread Starter
New Member
Redim in c++
Is it possible to redim field in c++ like Redim or Redim Preserve in VB?
I have a class with CString field but I dont know how many members I need for that field. (That depends and it is not allways same)
-
May 13th, 2002, 04:57 AM
#2
I don't think you can do it in C++.
In VB there it is available but I think in the background VB creates a new array , and copy's the values allready in it.
I think you'd better provide the maximum space you could think is needed.
-
May 13th, 2002, 06:28 AM
#3
Thread Starter
New Member
Thanks Swatty,
I need it because I want to "save" RAM resources maximum is possible, and program will create objects only if they is needed.
I did it in VB, I think must be a some way to do that in C++
-
May 13th, 2002, 07:33 AM
#4
Frenzied Member
Maybe you could try the vector class.. that will allocate more space when needed...
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
May 13th, 2002, 08:33 AM
#5
Of course there is a way, but it's more than one command. Use a CStringArray that is native to MFC and you'll be fine.
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.
-
May 25th, 2002, 01:37 AM
#6
Lively Member
you can use a pointer to create a dynamic array
-
May 25th, 2002, 07:11 AM
#7
Monday Morning Lunatic
If you don't understand pointers and memory management, don't use MFC.
Easiest way is a vector, like Jop says:
Code:
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
int main() {
cout << "Please enter some numbers, end with -1: " << flush;
vector<int> nums;
int num = 0;
while(!cin.eof()) {
cin >> num;
if(num == -1 || cin.fail()) {
// stop when we get either -1 or something
// that wasn't recognised as a number
break;
}
nums.push_back(num);
}
cout << endl << "You entered:" << endl;
copy(nums.begin(), nums.end(), ostream_iterator<int>(cout, "\n"));
cout << endl;
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 27th, 2002, 07:47 AM
#8
If I was already using MFC, I'd stay with their containers. The MFC containers are actually easy to use and don't have the confusing (for new people) iterators and such.
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.
-
May 27th, 2002, 11:21 AM
#9
Monday Morning Lunatic
They do use iterators, after a fashion...at least from what I remember (with POS_TYPE and all that, or something...).
I just like the way that everything in the STL works so seamlessly, for example you can copy a vector to a list with one line
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 27th, 2002, 02:15 PM
#10
No they don't. The only thing: a linked list uses POSITION, which is just a disgused node pointer. I admit it doesn't offer as much functionality as the STL, but still... it's native to MFC (and supports serialization BTW, STL doesn't do that)
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.
-
May 27th, 2002, 04:30 PM
#11
Monday Morning Lunatic
Originally posted by CornedBee
(and supports serialization BTW, STL doesn't do that)
True.
Although I doubt it would be too difficult to make some kind of generic operator>>/<< for an iterator range
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 28th, 2002, 09:51 AM
#12
I think it wouldn't be easy. MFC's serialization mechanism is quite complicated.
Well, you could probably override a function in the process and catch a specific byte sequence. Or you could create a dummy class that is created by the << iterator operator and serialized which in turn creates a STL object and fills it with the data when unserialized.
But it wouldn't be trivial.
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
|