|
Ah...well that adds another layer of difficulty.
Theres no way you can just declare a very large array at construction and fill it in as you go...?
Dynamic resizing isn't easy...I'm working on a class as we speak and i'm not sure i'd be able to fully explain.
First off i don't use new/delete, i use malloc/free.
you have to delete every new at the end of every code block otherwise you get memory leaks.
If you absolutely MUST dynamically resize your array I can only give you pointers...exact code I cannot.
basically use realloc/malloc/free
class CMyClass
{
public:
CMyClass() : m_nCount(0)
{ m_pBuff = malloc(sizeof(Investor)); }
~CMyClass(){ free(m_pBuff); }
void AddInvestor(Investor& newItem)
{
*(m_pBuff+m_nCount) = newItem;
m_nCount++;
m_pBuff = realloc(m_pBuff, sizeof(Investor)*(m_nCount+1)));
}
private:
UINT m_nCount;
Investor* m_pBuff;
};
Note: I don't know for 100% sure the above code is complete, I'm typping from the top of my head. I will however give a starting point.
The code only allocates to a larger size it does NOT shrink itself as required...It assumes there will be NO removal of items once in the array...Also it allocates memory one element at a time...this will fragment your memory. You'd have to allocate large chunks at construction fill them in, then have code in your AddInvestor() reallocate another large chunk and proceed as normal...
All in all this is quite alot of work.
Can I ask what this is for...? Have you considered perhaps using one of MFC's helper classes like CArray...??
It does the Sizing and allocation and stuff for you...
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Man you've been working hard on this stuff man, i don't know how to say thank you.
but the problem is that i must follow the instructor's specification!!!!!
if it depended on me i would have used a linked list but the thing is that i have to use exactly what he said if i don't want to get a zero in my project.
our instructor is so picky!
and as you say "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
i think this is what he wants make us go thru all mistakes??
well anyways here is my latest version of that stupid addInvestor(Investor in) method. see if you trace through it you probably won't find any problems
but the fact is that it adds the first element and crashes same as be4!!!
class Investors
{
// code........
int Investors::numOfInvestors = 0;
Investor* Investors:: investorsList = NULL;
// code........
void Investors:: addInvestor(Investor& in)
{
cout<< in<< endl;
cout<< "numOfInvestors at the beginning: "<< numOfInvestors<< endl;
numOfInvestors++;
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i < (numOfInvestors - 1); i++)
{
cout << "I am inside the first for loop and i = "<< i<< endl;
temp[i] = investorsList[i];
cout<< temp[i]<< endl;
}
delete [] investorsList;
investorsList = new Investor[numOfInvestors];
temp[numOfInvestors - 1] = in;
for( i = 0; i < numOfInvestors; i++)
{
investorsList[i] = temp[i];
}
insertionSort(investorsList, numOfInvestors);
}
delete [] temp;
cout<<"numOfInvestors at the end: "<< numOfInvestors<< endl;
}
<\pre>
AGAIN THANK YOU:rose: :rose: :rose: :rose: :rose: :rose:
|
|
|
|
|
Send me your cpp/h files unless theres more than one each in email.
It's hard for to lok at this code and guess whats really going on, unless I have the full thing.
Your code is really wide as well, so I keep having to scroll back and forth...It'll be much easier if I can code in my VC workspace.
So you MUST use new/delete for a dynamically growing array...you cannot use malloc and delete...?
That was the reason for the temp array creation...I see...
Yeah like i said..Actually....send me the entire project...that way theres no...missing links...
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Zip it too! so I don't get 5-6 files...Just one
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
How can I safely add helpstrings to MFC ActiveX control's ODL file?
I am working on an old activex control and wish to add helpstrings.
After adding the helpstrings, it compiles without any problem and shows in VB class browser.
However, the ClassWizard crashes anytime I try to use it, any tip?
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan.
|
|
|
|
|
A good whack might do it. (Delete the .clw file)
|
|
|
|
|
Hello -- i have a very wierd problem . i can't create a class starting with a capital C. when i:
Insert-->New Class
Enter the name that starts with a capital C -- the first C doesn't show up in the file name -- but lowercase 'c' works fine. This is as wierd as it gets . . . anybody got a clue on this one
also what is all this crap when i have the wizzards create a class:
#if !defined(AFX_USTOMER_H__E35819DB_8CEA_4883_A2DA_E78053B05B81__INCLUDED_)
#define AFX_USTOMER_H__E35819DB_8CEA_4883_A2DA_E78053B05B81__INCLUDED_
thanks,
tim
---------------------------------------
Tim Booher
|
|
|
|
|
It is not crap . They are called include file guard headers and they are used so that that particular file does not get included twice. The string AFX_USTOMER_H__E35819DB_8CEA_4883_A2DA_E78053B05B81__INCLUDED_ is generated randomly. For eg.
#ifndef _CUSTOMER_H_
#define _CUSTOMER_H_
.
.
.
.
#endif
Atul
Sonork 100.13714 netdiva
|
|
|
|
|
It it Hungarian notation to have all classes begin with a capital 'C'. VC interpret 'Custumer' as 'ustumer'. You could use 'CCustomer' or define your class whitout using the class-wizard.
/moliate
|
|
|
|
|
I don't know if it's Hungarian Notation, but i'm pretty sure that style was dropped with C++.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Starting class names with C was dropped? Heh, not by a LONGSHOT. Sure, the standard doesn't use that convention, but MS and others having been using long before STL was a glimmer in people's eyes.
And yes, dropping the capitial C from the start of the file name is a ... feature. Annoying if that isn't want you want. However, when creating a new class, you can specify the file names.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I never said starting classes with a C was dropped...read again!
I said It wasn't part of hungarian notation...
you know lpsz - long pointer to zero termintaed string
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Just TAB into the filename edit boxes and change the filenames there.
--Mike--
"There are only a limited number of jobs where they will ask to see the sausage. Most of them are in movies."
-- Christian Graus, 2/11/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
What is the best way to convert
1. points to pixels?
2. cm to pixels?
|
|
|
|
|
explanation in MFC, and from memory. take with large pinch of salt
Given a CDC* pDC , an integer specifying points pt , and another integer specifying centimeters cm :- points to pixels
- cm to pixels (explained above already)
int px = cm*1000;
CSize size(px,px);
pDC->HIMETRICtoDP(&size);
*** note: see documentation for HIMETRICtoDP: in MM_TEXT mapping mode, the measurements gained from this only reflect physical measurements when the ratio of logical coordinates to physical coordinates is 1/1. Not sure when this would matter though.
farewell goodnight last one out turn out the lights Smashing Pumpkins, Tales of a Scorched Earth
|
|
|
|
|
Battleaxe Document Explorer was posted sometime ago, but my bookmark fails.
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan.
|
|
|
|
|
I've been trying to do this for days.
Anyone have a clue for me?
Thank you
-Julie
|
|
|
|
|
I could tell you. But i enjoy watching others squirm.
Just kidding...
I think your referring to IWebBrowser2, C is for classes I is for Interfaces...slight difference.
Anywho...
You have to implement IDocHostUIHandler::ShowContextMenu
By returning S_OK you prevent IE (webbrowser control) from displaying it's default menu. returning S_FALSE allows default behavior.
Basically I think you'd just do your stuff (create menu) and return S_OK
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Ok. I'm writing a 2 pass assembler (for a class). Here's an annotated version of the base class...
class Asm
{
public:
Asm();
~Asm();
protected:
static HashTable symbolTable;
};
When I derive a class from Asm I get a linking error telling me that HashTable is unresolve. If I remove the static keyword it links fine.
1. So I'm guessing I can't have a static member in a base class because theres a possibility that the bass class will never be created. Is that right?
2. If this is the case then how do I share the symbol table between my derived classes, Pass1 and Pass2?
nay
|
|
|
|
|
nay wrote:
static HashTable symbolTable;
You have to initialize the HashTable just after your class definition by invoking its constructor maybe like
HashTable Asm::symbolTable();
This will be shared by all the instances of your Asm object.
Atul
Sonork 100.13714 netdiva
|
|
|
|
|
AAAHHHH... thank you very much. I initialized it in my cpp file like this...
HashTable Asm::symbolTable
thanks!
nay
|
|
|
|
|
Hi.
I started an MFC sample program that Prosise include in his book. I would like to save the source code, but not the enter project. Note that I started the project using AppWizard.
What files do I have to save from the project so I can always open that project up again? Do I have to save the entire probject including Debug? I have not save and/or remove any files yet because I do not work to lose any resource files.
Thanks,
Kuphryn
|
|
|
|
|
Delete the [debug] and [release] folders and back up the rest of the files into a zip.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
|
You do not the .ncb, .opt, .plg, .aps, or .clw either. All of these are re-generatable.
I wish some of the article writers here were aware of this.
|
|
|
|