Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CArray array gives undeclared identifier compile error

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
I have a class header file and in the header file I'm declaring a CArray variable as this:

Code:
[COLOR=green]CArray<FIELDOBJECTSTRUCT, FIELDOBJECTSTRUCT> m_aPageHeader;
[/color]

Then in the CPP file I'm trying to use the objects like this:

Code:
[COLOR=green]
m_aPageHeader.Add((FIELDOBJECTSTRUCT)fos);
[/color]

FIELDOBJECTSTRUCT is a structure defined in stdafx.h which is included in both the header and cpp files (I've also tried all combinations of included in one but not the other).

During compile I get the error:

error C2065: 'm_aPageHeader' : undeclared identifier

I have no clue what I need to do to use this. Could some one please help out a newb programmer? Thanks in advance.
 
Did you spell it correctly? Did you remember to #include the class header in the source file? Is that code inside a member function of the class? Did you remember to add the Classname:: to the function when defining that member function? Is there an error above that line of code?
 
Yes to all of those questions except the last one. No other error.

Also, if I declare the variable immediately above where I'm trying to use the .Add method, then I don't get the compile error.

But, I can't use the variable on the stack. I need it on the heap so I can use it throughout the application.
 
The CArray isn't on the heap either way, it is a member of the class. Can you post a bit more code. I assume it is something like this:
Code:
// MyClass.h
// ...
CMyClass
{
public:
  // ...
  void MyFunction();
  // ...
private:
  // ...
  CArray<FIELDOBJECTSTRUCT, FIELDOBJECTSTRUCT> m_aPageHeader;
  // ...
};
// ...
Code:
// MyClass.cpp

#include "MyClass.h"
// ...
void CMyClass::MyFunction()
{
  // ...
  m_aPageHeader.Add((FIELDOBJECTSTRUCT)fos);
  // ...
}
// ...
 
Sorry, you're right, it wouldn't be on the heap....don't know what I was thinking.

Anyway, the code you have posted is exactly what I have. I'll post the code anyway. One thing about it is, I tried using a dynamic array class first, which didn't work, then I tried with CArray (with the required afxtempl.h included), and it also didn't work.

Contents of Page.h

Code:
#pragma once

#include "stdafx.h"

class CPage
{
public:
	CPage(void);
	~CPage(void);

// Member variables
public:
	AeDynArray<FIELDOBJECTSTRUCT>	m_aPageHeader;			// array of page header objects;
	AeDynArray<FIELDOBJECTSTRUCT>	m_aPageFooter;			// array of page footer objects;

// Implementation
public:
	bool AddHeaderField(LPFIELDOBJECTSTRUCT lpFieldObject);
	bool AddHeaderField(POINT Origin,
						SIZE Size,
						LOGFONT Font,
						string FieldName = "",
						string Caption = "",
						string Text = "",
						string Expression = "",
						ACTIONS Action = Blank,
						string ActionField = "",
						BORDERFILL Style = None,
						char FillChar = ' ',
						int BorderWeight = 1);
};

Contents of Page.cpp

Code:
#include "StdAfx.h"
#include "Page.h"

CPage::CPage(void)
{
}

CPage::~CPage(void)
{
}

bool AddHeaderField(LPFIELDOBJECTSTRUCT lpFieldObject)
{
	FIELDOBJECTSTRUCT fos;
	memcpy( &fos, lpFieldObject, sizeof(FIELDOBJECTSTRUCT));

//	m_aPageHeader.Add( fos );

	return true;
}

bool AddHeaderField(POINT Origin,
					SIZE Size,
					LOGFONT Font,
					string FieldName,
					string Caption,
					string Text,
					string Expression,
					ACTIONS Action,
					string ActionField,
					BORDERFILL Style,
					char FillChar,
					int BorderWeight)
{
	FIELDOBJECTSTRUCT fos;
	fos.Action = Action;
	fos.ActionField = ActionField;
	fos.BorderWeight = BorderWeight;
	fos.Caption = Caption;
	fos.Expression = Expression;
	fos.FieldName = FieldName;
	fos.FillChar = FillChar;
	memcpy( &fos.font, &Font, sizeof( LOGFONT ));
	fos.ptOrigin = Origin;
	fos.Style = Style;
	fos.szSize = Size;
	fos.Text = Text;

	/*AeDynArray<FIELDOBJECTSTRUCT> m_aPageHeader;*/	/* <-- DOES NOT ERROR IF THIS LINE IS UNCOMMENTED */
	m_aPageHeader.Add( (FIELDOBJECTSTRUCT)fos );   /*  <-- LINE CAUSING error C2065: 
												    *  'm_aPageheader' : undeclared identifier */

	return true;
}

FIELDOBJECTSTRUCT is defined in StdAfx.h as the following

Code:
typedef struct tagFIELDOBJECTSTRUCT {
	// Contents
	string	FieldName;			// name of database field to use
	string	Caption;			// text placed next to field value text
	string	Text;				// used for constant text, do not set FieldName or Caption value
	string	Expression;			// a textual representation of an arithmetic expression, do not use
								// any other field values if using this
	
	// Position / Size
	POINT	ptOrigin;			// position of first occurance of field (top, left)
	SIZE	szSize;				// size of field rectangle

	// Action Codes
	ACTIONS	Action;				// action to take on field { sum, average, etc. }
	string	ActionField;		// field to take action on

	// Text formatting
	LOGFONT	font;				// Font structure containing font for this field

	// Border / Fill
	BORDERFILL	Style;			// Border / Fill style to use { Border, Fill, Both };
	char	FillChar;			// Character to fill rectangle with
	int		BorderWeight;		// Weight of border
} FIELDOBJECTSTRUCT, NEAR *PFIELDOBJECTSTRUCT, FAR *LPFIELDOBJECTSTRUCT;

And I'm trying to use AeDynArray which is included in stdafx.h using #include "aedynarray.h
 
I figured it out. I was being braindead and missed that none of my implementation functions had the class reference in the function name.

Once I put the CPage:: in front of the functions, no more error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top