Toon posts:

[C++/MFC] Array aanmaken van template type lukt niet*

Pagina: 1
Acties:
  • 63 views sinds 30-01-2008

Verwijderd

Topicstarter
Hallo allemaal,

Ik heb een MFC programma gemaakt en een klasse 'Klant'.
Ik wil graag een CArray<Klant,Klant&> klanten

aanmaken en hierin nieuwe klanten toevoegen. #include "afxtempl.h"
Heb ik ook include.

Probleem: werkt niet en geeft foutmelding.

Als iemand(expert) mij graag wil helpen....stuur ik het programma op zodat ie kan kijken wat ik fout doe.

reply je e-mil.

Bij voorbaat dank,
Io

  • moser
  • Registratie: Februari 2002
  • Laatst online: 26-03-2022

moser

And then there was silence

welke foutmelding krijg je?

kan je eens stuk code tonen waar je denkt dat de fout zit?

A busstation is where a bus stops,a trainstation is where train stops
On my desk, I have a workstation,
... No further comment.


Verwijderd

Topicstarter
Compiling...
KlantenLijst.cpp
d:\klantenlijst\klantenlijstdlg.h(19) : error C2143: syntax error : missing ';' before '<'
d:\klantenlijst\klantenlijstdlg.h(19) : error C2501: 'CArray' : missing storage-class or type specifiers
d:\klantenlijst\klantenlijstdlg.h(19) : error C2059: syntax error : '<'
d:\klantenlijst\klantenlijstdlg.h(19) : error C2238: unexpected token(s) preceding ';'
Generating Code...
Compiling...
KlantenLijstDlg.cpp
d:\klantenlijst\klantenlijstdlg.h(19) : error C2143: syntax error : missing ';' before '<'
d:\klantenlijst\klantenlijstdlg.h(19) : error C2501: 'CArray' : missing storage-class or type specifiers
d:\klantenlijst\klantenlijstdlg.h(19) : error C2059: syntax error : '<'
d:\klantenlijst\klantenlijstdlg.h(19) : error C2238: unexpected token(s) preceding ';'
Generating Code...
Error executing cl.exe.

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 22-01 23:51

NMe

Quia Ego Sic Dico.

Hoi, en welkom op GoT.

Aan replyen via mail doen we hier niet, en je code in jouw plaats debuggen al helemaal niet, dat kun je prima zelf. ;) Maar waar mogelijk kunnen we wel proberen je te helpen bij het oplossen van je probleem.

Begin maar eens met het aangeven van welke foutmelding je eigenlijk krijgt, dan kunnen we je misschien op weg helpen. Post meteen ook een stukje relevante (dus niet alle ;)) code, tussen [code]-tags. :)

Lees overigens ook Algemene gedragsregels (Netiquette) en Programming Beleid - De "quickstart" even door. :)

Ik maak meteen je topictitel wat duidelijker. "Array aanmaken" zegt niet gek veel over je probleem. ;)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


Verwijderd

Topicstarter
Modbreak:Persoonlijke hulp via email vragen doen we hier dus niet. Dat zou het hele nut van dit forum tenietdoen en sowieso hebben anderen er dan niets aan. Post maar wat relevante code, dan krijg je veel sneller hulp.

[ Voor 76% gewijzigd door NMe op 05-06-2006 17:37 ]


Verwijderd

Topicstarter
CArray<Klant,Klant&> klantLijst;

Toegevoegd en en krijgt error C2143 foutmelding

Verwijderd

Topicstarter
syntax error : missing ';' before '<'

Misschien maak ik in verkeerde constructor de Carray aan?

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 22-01 23:51

NMe

Quia Ego Sic Dico.

Heb je daar ook een context bij? Eén of twee regels code erboven en eronder zouden handig zijn. Ik vermoed dat je ofwel een puntkomma vergeten bent op de regel daarvoor, ofwel dat je de file met de Klant-klasse niet goed include.

Kun je trouwens de editknop gebruiken als je nog wat toe te voegen hebt aan een bericht? :)

[ Voor 18% gewijzigd door NMe op 05-06-2006 17:40 ]

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.


  • MLM
  • Registratie: Juli 2004
  • Laatst online: 12-03-2023

MLM

aka Zolo

d:\klantenlijst\klantenlijstdlg.h(19) : error C2501: 'CArray' : missing storage-class or type specifiers
hij kent CArray niet... weet je zeker dat je de juiste files wel geinclude hebt?
als je MS VS IDE gebruikt, kan je met contextmenu "Go to declaration" kijken of dat inderdaad het geval is :)

-niks-


Verwijderd

Topicstarter
Hoi,

Ik gebruik MS Visual C++. Ik include wel goed (denk ik maar wat de oorzaak van de fout is, kan ik niet vinden.

error C2143: syntax error : missing ';' before '<'
error C2501: 'CArray' : missing storage-class or type specifiers
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'

class CKlantenLijstDlg : public CDialog
{
// Construction
public:
CKlantenLijstDlg(CWnd* pParent = NULL); // standard constructor
CArray<Klant,Klant&> klantLijst;

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
Je denkt dat je goed include. Post eens de complete header als je kan.. die error die je krijgt duidt erop dat je niet goed include

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


Verwijderd

Topicstarter
class CKlant
{
public:
CKlant();
CKlant(CString naam, CString adres, CString plaats, CString tlnr);
virtual ~CKlant();

private:
CString cnaam;
CString cplaats;
CString cadres;
CString ctlnr;

public:
CString getNaam();
void setNaam(CString naam);

};


#include "stdafx.h"
#include "KlantenLijst.h"
#include "Klant.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CKlant::CKlant()
{
cnaam = "";
cadres = "";
cplaats = "";
ctlnr="";
}

CKlant::CKlant(CString naam, CString adres, CString plaats, CString tlnr)
{
cnaam = naam;
cadres = adres;
cplaats = plaats;
ctlnr=tlnr;
}

CKlant::~CKlant()
{

}

CString CKlant::getNaam()
{
return cnaam;
}

void CKlant::setNaam(CString naam)
{
cnaam = naam;
}

// KlantenLijstDlg.h : header file
//

#if !defined(AFX_KLANTENLIJSTDLG_H__55D4DDF1_B28B_4E60_A000_F24DFC324BD6__INCLUDED_)
#define AFX_KLANTENLIJSTDLG_H__55D4DDF1_B28B_4E60_A000_F24DFC324BD6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CKlantenLijstDlg dialog

class CKlantenLijstDlg : public CDialog
{
// Construction
public:
CKlantenLijstDlg(CWnd* pParent = NULL); // standard constructor

//CArray<Klant,Klant&> klantLijst;

// Dialog Data
//{{AFX_DATA(CKlantenLijstDlg)
enum { IDD = IDD_KLANTENLIJST_DIALOG };
CListBox m_lijst;
CString m_naam;
CString m_plaats;
CString m_tlnr;
CString m_adres;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CKlantenLijstDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CKlantenLijstDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnToevoegen();
afx_msg void OnSelchangeLijst();
afx_msg void OnLeeg();
afx_msg void OnVerwijderen();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_KLANTENLIJSTDLG_H__55D4DDF1_B28B_4E60_A000_F24DFC324BD6__INCLUDED_)

// KlantenLijstDlg.cpp : implementation file
//

#include "stdafx.h"
#include "KlantenLijst.h"
#include "KlantenLijstDlg.h"
#include "Klant.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CKlantenLijstDlg dialog

CKlantenLijstDlg::CKlantenLijstDlg(CWnd* pParent /*=NULL*/)
: CDialog(CKlantenLijstDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CKlantenLijstDlg)
m_naam = _T("");
m_plaats = _T("");
m_tlnr = _T("");
m_adres = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CKlantenLijstDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKlantenLijstDlg)
DDX_Control(pDX, IDC_LIJST, m_lijst);
DDX_Text(pDX, IDC_NAAM, m_naam);
DDV_MaxChars(pDX, m_naam, 100);
DDX_Text(pDX, IDC_PLAATS, m_plaats);
DDV_MaxChars(pDX, m_plaats, 100);
DDX_Text(pDX, IDC_TLNR, m_tlnr);
DDV_MaxChars(pDX, m_tlnr, 10);
DDX_Text(pDX, IDC_ADRES, m_adres);
DDV_MaxChars(pDX, m_adres, 100);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CKlantenLijstDlg, CDialog)
//{{AFX_MSG_MAP(CKlantenLijstDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_TOEVOEGEN, OnToevoegen)
ON_LBN_SELCHANGE(IDC_LIJST, OnSelchangeLijst)
ON_BN_CLICKED(IDC_LEEG, OnLeeg)
ON_BN_CLICKED(IDC_VERWIJDEREN, OnVerwijderen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKlantenLijstDlg message handlers

BOOL CKlantenLijstDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here


return TRUE; // return TRUE unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CKlantenLijstDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CKlantenLijstDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CKlantenLijstDlg::OnToevoegen()
{
UpdateData();

CKlant naw(m_naam,m_adres,m_plaats,m_tlnr);
m_lijst.AddString(naw.getNaam());
m_naam="";

UpdateData(FALSE);
Invalidate();
}

void CKlantenLijstDlg::OnSelchangeLijst()
{
m_lijst.GetText(m_lijst.GetCurSel(), m_naam);
UpdateData(FALSE);
}

void CKlantenLijstDlg::OnLeeg()
{
int result = AfxMessageBox ("Wilt u alles verwijderen?", MB_YESNO|MB_ICONQUESTION);
if(result == IDYES)
{
m_lijst.ResetContent();
}

}

void CKlantenLijstDlg::OnVerwijderen()
{
int index = m_lijst.GetCurSel();

if (index != LB_ERR)
{
m_lijst.DeleteString(index);
}
else
{
AfxMessageBox ("Selecteer een klant in de lijst en daarna druk op 'Verwijderen'!",MB_ICONINFORMATION|MB_OK);
}
}

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
1: Include je Afxtempl.h in stdafx.h? Zo niet, zet 'm daar erbij (alternatief is om het alleen in KlantenLijstDlg.h te includen)
2: De klasse Klant is niet bekend in KlantenLijstDlg.h, dus je zult ook Klant.h moeten includen in KlantenLijstDlg.h

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


Verwijderd

Topicstarter
// KlantenLijstDlg.h : header file
//
#include "afxtempl.h"
#include "Klant.h"

#if !defined(AFX_KLANTENLIJSTDLG_H__55D4DDF1_B28B_4E60_A000_F24DFC324BD6__INCLUDED_)
#define AFX_KLANTENLIJSTDLG_H__55D4DDF1_B28B_4E60_A000_F24DFC324BD6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CKlantenLijstDlg dialog

class CKlantenLijstDlg : public CDialog
{
// Construction
public:
CKlantenLijstDlg(CWnd* pParent = NULL); // standard constructor

CArray<Klant,Klant&> klantLijst;


1) nee ik include ze apart
2) is het zo goed?

Verwijderd

Topicstarter
mijn e adres is : starmatrix at home.nl

Verwijderd

Topicstarter
Ik stuur het hele bestand op zodat je kunt zien wat ik fout doe?

Verwijderd

Topicstarter
mail mij

  • NMe
  • Registratie: Februari 2004
  • Laatst online: 22-01 23:51

NMe

Quia Ego Sic Dico.

Exit. Ik heb meerdere keren gezegd dat we niet aan emailen doen, en ook mijn andere sturende opmerkingen sla je in de wind. Als je er echt niet uitkomt kun je een nieuw topic openen, maar ga eerst maar eens doen wat ik hier zei: [rml]-NMe- in "[ C++/MFC] Array aanmaken van template ty..."[/rml].

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.

Pagina: 1

Dit topic is gesloten.