CList bzw. CArray

Winner

Erfahrenes Mitglied
Hallo zusammen,

ich habe nicht wirklich ein Problem, denn noch kann mir vielleicht einer erklären wieso das eine funktioniert und das andere nicht. Hier mal kurz mein Code den ich habe.

Code:
typedef struct {char tmp[128];} _tmp; //damit ich ein Char Array in eine CList oder CArray einfügen kann

//Auszüge Funktionsinhalte
//Deklaration:
CList<_tmp,_tmp> liInputData; 
CArray<_tmp,_tmp> cArraytxt;

liInputData.AddTail(this->szInputNr);   //szInputNr ist ein _tmp
cArraytxt.Add(this->szInputNr);


//nachher alles wieder auslesen was aufgenommen wurde

this->szInputNr =  liInputData.GetAt(i) ;   //und das will er nicht übersetzen
this->szInputNr = cArraytxt.GetAt(i); //Funktioniert sauber

Habe auch schon probiert bei der Zuweisung "this->szInputNr = liInputData.GetAt(i) ;" einen typecast zu benutzen allerdings ohne erfolg.

Fehlermeldung sieht so aus: rror C2664: 'CDlgGISI::_tmp &__thiscall CList<struct CDlgGISI::_tmp,struct CDlgGISI::_tmp>::GetAt(struct __POSITION *)' : Konvertierung des Parameters 1 von 'int' in 'struct __POSITION *' nicht moeglich
Die Konvertierung eines ganzzahligen Typs in einen Zeigertyp erfordert ein reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat

VS 6.0 C++

Kann mir das einer erklären, wieso das nicht mit der CList klappt und mit dem CArray wunderbar...

Vielen Dank...
 
Moin,

der Grund steht doch in Deiner Fehlermeldung :suspekt:

Siehe hierzu auch die VS C++-Hilfe:
Code:
CList::GetAt@import url(msdn_ie4.css); CList::GetAt

 TYPE& GetAt( POSITION position  );
 TYPE GetAt( POSITION position )  const;
 Return Value
 See the return value description for GetHead.
 Parameters
 TYPE
 Template parameter specifying the type of object in the  list.
 position
 A POSITION value returned by a previous  GetHeadPosition or Find member function call.
 Remarks
 A variable of type POSITION is a key for the list. It is not the same  as an index, and you cannot operate on a POSITION value yourself.  GetAt returns the element (or a reference to the element) associated with  a given position. 
 You must ensure that your POSITION value represents a valid position  in the list. If it is invalid, then the Debug version of the Microsoft  Foundation Class Library asserts.

Du musst dort also eine Wert vom Typ "position" angeben ! ! !
CArray erwartet hier einen Integer als Index - vgl. wieder die Hilfe:
Code:
CArray::GetAt@import url(msdn_ie4.css);CArray::GetAt

 This member function retrieves the array element at the specified index.
 Syntax

 TYPE GetAt( int nIndex ) const;


In der Hilfe findest Du noch mehr dazu ;-]

Gruß
Klaus
 
Zurück