Click here to Skip to main content
15,915,764 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionStatic or nonstatic member function? Pin
Vicord Chrane7-Jun-04 15:23
Vicord Chrane7-Jun-04 15:23 
AnswerRe: Static or nonstatic member function? Pin
Ryan Binns7-Jun-04 18:05
Ryan Binns7-Jun-04 18:05 
GeneralEnumerating Internet Ports Pin
Archer2827-Jun-04 13:24
Archer2827-Jun-04 13:24 
GeneralCan't Connect to the server Pin
osal7-Jun-04 11:50
osal7-Jun-04 11:50 
Questionis application open? Pin
pnpfriend7-Jun-04 10:00
pnpfriend7-Jun-04 10:00 
AnswerRe: is application open? Pin
David Crow7-Jun-04 10:48
David Crow7-Jun-04 10:48 
AnswerRe: is application open? Pin
Archer2827-Jun-04 13:21
Archer2827-Jun-04 13:21 
GeneralCArray Pin
brdavid7-Jun-04 9:56
brdavid7-Jun-04 9:56 
I have a fairly complex CArray object built where problems seem to be happening.

The CArray object looks as follows
<code>
class Items
{
public:
	Items(){}
	Items::Items(const Items &pCopy)
	{
		operator= (pCopy);
	}

	Items& Items::operator =(const Items& Array)
	{
		ItemGroup = Array.ItemGroup;
		ItemCategory = Array.ItemCategory;
		ItemCode = Array.ItemCode;
		ItemDescription = Array.ItemDescription;
		ItemAmount = Array.ItemAmount;

		return *this;
	} 

	CString ItemGroup;
	CString ItemCategory;
	CString ItemCode;
	CString ItemDescription;
	int ItemAmount;
};

class StartingItems
{
public:
	StartingItems(){}
	StartingItems::StartingItems(const StartingItems &pCopy)
	{
		operator= (pCopy);
	}

	StartingItems& StartingItems::operator =(const StartingItems& Array)
	{
		for(int i=0; i<Array.m_Items.GetSize(); i++)
			m_Items.Add(Array.m_Items.GetAt(i));

		Era = Array.Era;
		Age = Array.Age;
		EraCode = Array.EraCode;
		AgeCode = Array.AgeCode;

		return *this;
	} 

	CArray<Items, Items> m_Items;
	CString Era;
	CString Age;
	CString EraCode;
	CString AgeCode;
};
</code>


Then I define the following variable
CArray<StartingItems,StartingItems> m_pItemsMap;


Now when I add StartingItems objects to m_pItemsMap I can see the array growing. But when I add objects to m_pItemsMap[index].m_Items nothing happens. I've noticed that the copy constructor is getting called numerous times in the StartingItems object and when it is called there is nothing the Copy parameter is empty of any values. Kinda like putting stuff in a bag with no bottom. You can see the stuff going in but the bag is always empty.

My adding code is the following
StartingItems pSI;

            pSI.Age = AgeDescription;
            pSI.Era = EraDescription;
            ItemIndex = m_pItemsMap.Add(pSI);

            Items pI;
            pI.ItemAmount = atoi(Amount);
            pI.ItemCategory = ItemCategoryCode;
            pI.ItemCode = ItemCode;
            pI.ItemDescription = Description;
            pI.ItemGroup = ItemGroupCode;
            pSI.m_Items.Add(pI);

            pSI.Age = AgeCode;
            pSI.Era = EraCode;
            m_pItemsMap.SetAt(ItemIndex, pSI);


Does anyone see anything wrong? Am i using this object correctly. Obviously I must be doing something incorrectly. Wink | ;)

Thanks!
GeneralRe: CArray Pin
David Crow7-Jun-04 10:33
David Crow7-Jun-04 10:33 
GeneralRe: CArray Pin
brdavid7-Jun-04 11:41
brdavid7-Jun-04 11:41 
Generalselect a single file right click menu Pin
skoizumi291107-Jun-04 9:20
sussskoizumi291107-Jun-04 9:20 
GeneralRe: select a single file right click menu Pin
David Crow7-Jun-04 10:07
David Crow7-Jun-04 10:07 
GeneralRe: select a single file right click menu Pin
skoizumi291107-Jun-04 10:20
sussskoizumi291107-Jun-04 10:20 
GeneralRe: select a single file right click menu Pin
David Crow11-Jun-04 2:04
David Crow11-Jun-04 2:04 
GeneralRe: select a single file right click menu Pin
skoizumi2911013-Jun-04 15:34
sussskoizumi2911013-Jun-04 15:34 
GeneralRe: select a single file right click menu Pin
David Crow14-Jun-04 2:32
David Crow14-Jun-04 2:32 
GeneralCreateThread and Hooks Pin
Spiritofamerica7-Jun-04 8:29
Spiritofamerica7-Jun-04 8:29 
GeneralRe: CreateThread and Hooks Pin
David Crow7-Jun-04 8:59
David Crow7-Jun-04 8:59 
GeneralRe: CreateThread and Hooks Pin
Blake V. Miller7-Jun-04 15:34
Blake V. Miller7-Jun-04 15:34 
GeneralRe: CreateThread and Hooks Pin
Ryan Binns7-Jun-04 18:22
Ryan Binns7-Jun-04 18:22 
GeneralRe: CreateThread and Hooks Pin
Spiritofamerica7-Jun-04 19:48
Spiritofamerica7-Jun-04 19:48 
GeneralHtml Context Help in CView Pin
MikeF_7-Jun-04 7:06
MikeF_7-Jun-04 7:06 
GeneralExpert's opinions pz Pin
peachieboy7-Jun-04 7:06
peachieboy7-Jun-04 7:06 
GeneralRe: Expert's opinions pz Pin
David Crow7-Jun-04 7:14
David Crow7-Jun-04 7:14 
GeneralRe: Expert's opinions pz Pin
Henry miller7-Jun-04 10:00
Henry miller7-Jun-04 10:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.