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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! I'm losing it ! 2

Status
Not open for further replies.

josphin

Programmer
Apr 5, 2003
19
BE
Hi,
I declare the CArray variable array as follows in the KassaDlg.h file:

class CKassaDlg : public CDialog
{
// Construction
public:
CKassaDlg(CWnd* pParent = NULL); // standard constructor
CArray <CProducten, CProducten&> array; //declaration of array variable
// Dialog Data
//{{AFX_DATA(CKassaDlg)
enum { IDD = IDD_KASSA_DIALOG };
//}}AFX_DATA
...

I want to use the variable array in the following member function:
void CArtikelDlg::OnButtonvoegToe()
{
// TODO: Add your control notification handler code here
CProducten product; //tijdelijk product aanmaken
m_ArtBarcode = product.barcode;
m_ArtNaam = product.naam;
m_ArtPrijs = product.prijs;
m_ArtStock = product.stock;
array.Add(product);
}
this is in the file called: ArtikelDlg.cpp
In this file, I included the following header files:

#include &quot;stdafx.h&quot;
#include &quot;Kassa.h&quot;
#include &quot;KassaDlg.h&quot; //for use of the array variable, &quot;I THOUGHT !!!!!
#include &quot;ArtikelDlg.h&quot;
#include &quot;LeveringenDlg.h&quot;
#include &quot;Producten.h&quot;
#include <afxtempl.h> //for use of CArray

now when i compile i always get the following errors:
:\Documents and Settings\josphin1\Mijn documenten\PROFCT info\Kassa\ArtikelDlg.cpp(66) : error C2065: 'array' : undeclared identifier
C:\Documents and Settings\josphin1\Mijn documenten\PROFCT info\Kassa\ArtikelDlg.cpp(66) : error C2228: left of '.Add' must have class/struct/union type

WHAT CAN I DO ???
 
The variable “array” is defined in the class CkKassaDlg and you are trying to access it in the class CArtikelDlg.

That’s just not right. A member variable is a “member” variable not a “global” variable.

-pete
 
but i did include the KassaDlg.h file, where array is declared.
No sweat, how can i make it a global variable ???
 
I think array is a reserved or key word in VC++. Probably you want to try changing the name.


Good LUcks!
 
it don't work... changed the name to ProdArray ==> same errors.
Thx anyway!
 
>> No sweat, how can i make it a global variable ???

Ouch… I didn’t mean to suggest that you use global variables. You want to think about your design and place the variable where it makes the most sense. If other classes need access to it then you provide accessor methods from the class that &quot;owns&quot; the array. Go and research the MVC (Model View Controler) architecture.

The MFC Document/View architecture is similar to MVC and uses the CDocument derivatives to maintain application state. Then the CDocument class can provide accessor/mutator methods to the array object.

-pete
 
Ok, When or where in the code the constructor is being instantiated?

Don't you think you have to instantiate your cKassaDlg somewhere in your code.

Ignore this if you already have an answer.


GoodLucks!
 
I declare the CArray variable array as follows in the KassaDlg.h file:

class CKassaDlg : public CDialog
{
// Construction
public:
CKassaDlg(CWnd* pParent = NULL); // standard constructor
CArray <CProducten, CProducten&> array; //declaration of array variable
// Dialog Data
//{{AFX_DATA(CKassaDlg)
enum { IDD = IDD_KASSA_DIALOG };
//}}AFX_DATA
...

i think (read: hope) you mean this...
 
What you have is correct in the header file.

I think in your cpp file:

you have to define constructor for the class as below:

CArtikelDlg::CKassaDlg()
{
}

cuz this is what instantiates cKassaDlg class constructor. Then you should be able to refer to the variable in the member function like you have it at this point.


Well, thats all I got.

Good Luks!
 
Code:
CArtikelDlg::CKassaDlg()
{
}

what is that? that just does not look right at all.

-pete
 
i don't think it's right either.
i think i must create some public member functions to acces the CArray. But that ain't easy at all, i guess. I don't get the whole pointer and reference stuff, and isn't that what you need when working with arrays ???

Thanks for your help you guys !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top