CList with user defined type is not working
-
within my class i created a struct and a CList template containing the struct. but i something goes wrong when i try to add a struct variable to the CList object. Whats wrong? #include "StdAfx.h" #include "Afxtempl.h" //HoleVok.h class CHoleVok { private: typedef struct TABELLE { CString strSQL; CString intTID; int intVokAnzahl; CList clistGeprueft; }; CArray arrTabellen; CDatabase *db; public: bool fnConnect(CDaoDatabase &db); }; ___________________________________________ #include "stdafx.h" #include "HoleVok.h" //HoleVok.cpp bool CHoleVok::fnConnect(CDaoDatabase &db) { TABELLE tabTest1; tabTest1.clistGeprueft.AddTail(20); tabTest1.clistGeprueft.AddTail(21); tabTest1.intTID = 4; tabTest1.intVokAnzahl = 200; tabTest1.strSQL = "Das Wetter ist schoen"; arrTabellen.Add(tabTest1); return true; }
-
within my class i created a struct and a CList template containing the struct. but i something goes wrong when i try to add a struct variable to the CList object. Whats wrong? #include "StdAfx.h" #include "Afxtempl.h" //HoleVok.h class CHoleVok { private: typedef struct TABELLE { CString strSQL; CString intTID; int intVokAnzahl; CList clistGeprueft; }; CArray arrTabellen; CDatabase *db; public: bool fnConnect(CDaoDatabase &db); }; ___________________________________________ #include "stdafx.h" #include "HoleVok.h" //HoleVok.cpp bool CHoleVok::fnConnect(CDaoDatabase &db) { TABELLE tabTest1; tabTest1.clistGeprueft.AddTail(20); tabTest1.clistGeprueft.AddTail(21); tabTest1.intTID = 4; tabTest1.intVokAnzahl = 200; tabTest1.strSQL = "Das Wetter ist schoen"; arrTabellen.Add(tabTest1); return true; }
The CList is a template. You need to define what is being stored in its definition. such as. typedef struct TABELLE { CString strSQL; CString intTID; int intVokAnzahl; CList clistGeprueft; }; After this the following works fine. TABELLE NewTab; NewTab.clistGeprueft.AddTail(20); NewTab.clistGeprueft.AddTail(21); NewTab.clistGeprueft.AddTail(24); int myval; myval = NewTab.clistGeprueft.GetHead(); POSITION pos = NewTab.clistGeprueft.GetHeadPosition(); myval = NewTab.clistGeprueft.GetNext(pos); myval = NewTab.clistGeprueft.GetNext(pos); myval = NewTab.clistGeprueft.GetNext(pos); myval = NewTab.clistGeprueft.GetNext(pos); NOTE the last line here fails because the list had 3 elements and I did not test for a NULL position. ================== The original message was: within my class i created a struct and a CList template containing the struct. but i something goes wrong when i try to add a struct variable to the CList object. Whats wrong?
#include "StdAfx.h"
#include "Afxtempl.h"class CHoleVok
{
private:typedef struct TABELLE
{
CString strSQL;
CString intTID;
int intVokAnzahl;
CList clistGeprueft;
};CArray arrTabellen;
CDatabase *db;
public:
bool fnConnect(CDaoDatabase &db);};
___________________________________________
#include "stdafx.h"
#include "HoleVok.h"bool CHoleVok::fnConnect(CDaoDatabase &db)
{
TABELLE tabTest1;
tabTest1.clistGeprueft.AddTail(20);
tabTest1.clistGeprueft.AddTail(21);
tabTest1.intTID = 4;
tabTest1.intVokAnzahl = 200;
tabTest1.strSQL = "Das Wetter ist schoen";arrTabellen.Add(tabTest1);
return true;
} -
The CList is a template. You need to define what is being stored in its definition. such as. typedef struct TABELLE { CString strSQL; CString intTID; int intVokAnzahl; CList clistGeprueft; }; After this the following works fine. TABELLE NewTab; NewTab.clistGeprueft.AddTail(20); NewTab.clistGeprueft.AddTail(21); NewTab.clistGeprueft.AddTail(24); int myval; myval = NewTab.clistGeprueft.GetHead(); POSITION pos = NewTab.clistGeprueft.GetHeadPosition(); myval = NewTab.clistGeprueft.GetNext(pos); myval = NewTab.clistGeprueft.GetNext(pos); myval = NewTab.clistGeprueft.GetNext(pos); myval = NewTab.clistGeprueft.GetNext(pos); NOTE the last line here fails because the list had 3 elements and I did not test for a NULL position. ================== The original message was: within my class i created a struct and a CList template containing the struct. but i something goes wrong when i try to add a struct variable to the CList object. Whats wrong?
#include "StdAfx.h"
#include "Afxtempl.h"class CHoleVok
{
private:typedef struct TABELLE
{
CString strSQL;
CString intTID;
int intVokAnzahl;
CList clistGeprueft;
};CArray arrTabellen;
CDatabase *db;
public:
bool fnConnect(CDaoDatabase &db);};
___________________________________________
#include "stdafx.h"
#include "HoleVok.h"bool CHoleVok::fnConnect(CDaoDatabase &db)
{
TABELLE tabTest1;
tabTest1.clistGeprueft.AddTail(20);
tabTest1.clistGeprueft.AddTail(21);
tabTest1.intTID = 4;
tabTest1.intVokAnzahl = 200;
tabTest1.strSQL = "Das Wetter ist schoen";arrTabellen.Add(tabTest1);
return true;
}Benedikt, I missed what the lt gt signs did to the code. Now my sample worked. Can you describe what goes wrong? Given the code is not being post clearly is the problem with the CList or the CArray? The following is adding the "pre" html prior to the code just to see what it looks like.
typedef struct TABELLE
{
CString strSQL;
CString intTID;
int VokAnzahl;
CList clistGeprueft;
}; -
Benedikt, I missed what the lt gt signs did to the code. Now my sample worked. Can you describe what goes wrong? Given the code is not being post clearly is the problem with the CList or the CArray? The following is adding the "pre" html prior to the code just to see what it looks like.
typedef struct TABELLE
{
CString strSQL;
CString intTID;
int VokAnzahl;
CList clistGeprueft;
};