|
But I don't want to fix the number of elements......I want to create an infinite "array"......I can insert elements in this list unlimited........
Do you know how to do that?????
THANK YOU
|
|
|
|
|
> I want to create an infinite "array"
You'll need a computer with infinite memory. Not all users of your application will be able to buy one.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
The best that I think you can do is use some program variable that is set. It is difficult to contemplate what an infinite size array might be
int* pNumber = new int [SomeProgramVariable];
for (inti=0;i
|
|
|
|
|
Ouch .. I got bit by those $%#@&*(%$ tags again.
|
|
|
|
|
Use a MFC CArray or a STL vector.
|
|
|
|
|
The prolbem is that you are allocating enough memory to hold one int item only!!
so your code is accessing invalid memory!
the statement :
*(pPtr+i) = i; //this is going beyond the memory pointed to by pPtr!!
To create a dynamic array, you need to know the number of elements in it and then allocate it:
void MakeArray(int nCount)
{
int * pPtr = new int[nCount];
if (pPtr)
{
for (int i=0; i < nCount; ++i)
{
*(pPtr+i) = i; //This is ok
pPtr[i] = i; //is same as above!
.....
}
//Free the memory
delete [] pPtr;
}
}
Mh2!
|
|
|
|
|
You guys are great!!!!!!!
|
|
|
|
|
The correct code is as follows.
int *pPtr;
pPtr = new int[10]; //U were allocating for only a single integer
for (int i=0; i<10; i++)//u were doing 11 iterations 0 to 10
{
*(pPtr+i) = i;
}
delete[] pPtr; //u were deleting only a single element
void (*p[10]) (void (*)());
|
|
|
|
|
I am trying to use a grid control supplied on this web site. however, when i include the custom control on my form (im using an sdi app) i get the above error message, am I doing something wrong!?
thanks
|
|
|
|
|
I was in good old Chapters the other day I picked up one of the Stroustrup series books and read up a little on the topic, but I did not have time to finish. Does any one know of a good web site that explains the concepts behind implementing the visitor concept?
Thanks,
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
|
Sweet! thanks a bunch Tomasz!
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Whats the difference....
(char*) blah
char* blah
|
|
|
|
|
(char*) blah is a C style cast - its telling the complier to treat the expression blah as a pointer to char.
char* blah is a declaration of blah, or possibly just an argument type if used in the decl of a function argument.
|
|
|
|
|
I've got a project here that's supposed to open a custom-formatted text file (its just a record file delimited with the | (pipe) symbol) and I'm having the darnedest trouble trying to figure out how to open it, work with the CArchive, and assign values to the variables I already have.
I know this is easy, but I don't know enough MFC/STL to do this. I generated a project with the MFC AppWiz (SDI, no database support), so I've got standard Wizard-generated code to work with. It'll be easiest if someone has example code for me, because I am totally at a loss.
|
|
|
|
|
Say goodbye to CArchive. If your program has a custom format, you need to override OnOpenDocument and OnSaveDocument in your CDocument-derived class. Use stdio's FILE, MFC's CFile, STL's iostream or Windows API to read/write file contents - CArchive will not help here.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I had a practice DOS version of this program running, using fstream, but unfortunately, the read/write operations are slow. In the Windows version I'm writing now, I'd like to have immediate response when moving back and forth between records.
Will fstream be more responsive in Windows than it was in DOS, or can I expect the same delay when it reads/writes the disk? I'm assuming it'll be as slow, because fstream isn't buffered like CArchive/CFile.
Right now I'm reading Leo Moll's Property Sheet View article. It looks like it can help me out. I think I'm missing a lot more information than just working with the file I/O.
|
|
|
|
|
Is fstream the usual way how people do file IO. In my case I wanted to save a string to a file. I didnt know whether htis should go into a CArchive object. in fact I havent got a clue when it comes to CArchive and serialisation. It seems a complicated subject.... Can I put strings/ints etc into archives and then pass them to serialize()
thanks in advance
|
|
|
|
|
If you're using MFC, just (typing from memory here, not pasting - so excuse any typos -the help for CFile::Write has examples I believe)
-----
CFile savestring;
savestring.Open("Myfile.txt", CFile::modeWrite);
size = myString.getLength()+1; //use whatever you need. Not sure if buffer rqd.
savestirng.Write( myString.getBuffer(size), size);
savestring.Close();
If you have a format for the line, you can just as easily write out your storage class in the 'Write'.
CArchive seemed like more of a hassle than just writing things out myself - I messed with it for awhile but had problems with the arrangement of the various macros for Implement_Dynamic and whatnot.
--Mark Terrano
www.ensemblestudios.com
(Creators of the Age of Empires series)
|
|
|
|
|
template < template < class TYPE > class COORD >
class vector : public COORD
{
public:
TYPE& operator[]( const int nIndex )
{
return ( ( TYPE *) this[ nIndex] );
}
};
|
|
|
|
|
|
Infinite recursion... the subscript operator (I think that’s what its called) calls itself over and over again...
BTW: Are you using the STL's? I don’t think you should be using ‘vector’ as a class name (unless you've wrapped it all in a common namespace).
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I think I find what is the problem.
The problem become from VC++ which doesn't support nested templates.
|
|
|
|
|
> The problem become from VC++ which doesn't support nested templates.
sure it does, how would the STL work? All the iterators declared within the class that they apply to. e.g. vector::iterator.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
> The problem become from VC++ which doesn't support
> nested templates.
Hmmm... Are you simply trying to derive vector from template class COORD?
If yes, it should look like this:
template <class T>
class vector : public COORD<T>
{
// vector members here
};
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|