generic methode curr()
-
ich habe einen G_BAG mit strings gemacht, nun möchte ich mit einen courser den wer(string) mit hilfe der methode curr(). habs so probiert:
string tempStr
string* pstr;while(SlmysCourser.next() != NULL)
{
tempStr = entry.SLMY;pstr = SlmysCourser.curr(); // * siehe fehler anzeige unten
if(tempStr != *pstr)
{foundSlmys.add(tempStr);
numberSlmy++;
}
}D:\HTE_WSP\U\VOBS\HTE\CODE\COMMON\CheckWorkloadAnalysetool\AnalyseTool\Cc_SLMYs.cpp(316) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class
-
nooby schrieb:
ich habe einen G_BAG mit strings gemacht, nun möchte ich mit einen courser den wer(string) mit hilfe der methode curr(). habs so probiert
das sagt (mir zumindest) so gut wie nichts, wäre ganz nett, wenn du ein bisschen mehr infos hergeben könntest.
die fehlermeldung ist außerdem ein bisschen abgeschnitten.
wie sieht denn die signatur von curr aus (was gibt curr zurück?)
-
Compiling...
Cc_SLMYs.cpp
D:\HTE_WSP\U\VOBS\HTE\CODE\COMMON\CheckWorkloadAnalysetool\AnalyseTool\Cc_SLMYs.cpp(316) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >' (or there is no acceptable conversion)
Error executing cl.exe.
Creating browse info file...AnalyseTool.lib - 1 error(s), 0 warning(s)
das ist die ganze fehler meldung....
hier ein ausschnitt von der beschreibung von curr():Current position
const T &curr() const;
Returns a reference to the object referred by the current position of the iterator.
Preconditions: The cursor must be connected to a collection, and a current element must be defined.const T &operator*() const;Equivalent to curr().
const T *find(const T &k);das ist der code der ganzen funktion:
int Cc_SLMYs::numberOfSLMYs() { ifstream datei; datei.open(LogFileName); int numberSlmy = 0; int lineNumber = 2; string zeile; string tempStr; string* pstr; G_BAG (string) foundSlmys; G_Cursor <string> SlmysCourser (foundSlmys); Cc_SLMYs entry; //spalte um spalte wird nach der wortkette "FAILED" untersucht while(getline(datei, zeile)) { entry = lineReader(lineNumber); lineNumber++; while(SlmysCourser.next() != NULL) { tempStr = entry.SLMY; pstr = SlmysCourser.curr(); if(tempStr != *pstr) { foundSlmys.add(tempStr); numberSlmy++; } } } return numberSlmy; }/edit: bitte lesen und tun: sfds
-
hier noch die beschreibung für G_BAG:
DESCRIPTION
A G_Bag<T,IMP> is an abstract parameterized unordered homogeneous collection class whose elements are of type T. Copying and assigning elements of type T must be possible. The actual data structure for the implementation is chosen through the second type parameter IMP. Bags can contain any number of duplicate elements. Equality between elements normally is determined by using operator==. The user can override this behavior by defining an operation class that is passed as the third argument to the instantiation macro GIO_BAG. See chapter ,,Collections with Plugable Implementations" on page 29 for more information.IMPLEMENTATIONS
The following classes can be used as implementation classes for G_Bag:#include <gchash.h>
class G_ClosedHashTable<T,OP>;
T must have operator== and operator G_HashValue defined if you do not specify your own operation class and if T is not a built-in type. If you supply an operation class, this must have the static members equals and hash.
Closed hash tables use special values to mark empty slots in the table. For built-in types, the value zero is used as the marker value. For user-defined types, the object constructed by the default constructor, or if there is no constructor, an object with a zero bit pattern is used as the marker value. As a consequence, T must have a default constructor, or no constructor at all if it is a user defined type. Furthermore, it is not allowed to add objects that are equal to the marker value.Closed hash tables have a smaller memory overhead than open hash tables. But you should only use them if the number of duplicate elements is small compared to the total number of elements. Otherwise you get large clusters with large empty spaces in between, which can dramatically increase the time needed to locate a specific element. Furthermore, you should note that closed hash tables move their members in memory, so that you cannot use them if you want to keep pointers to members of the bag.
leider verstehe ich es nicht so gut und bisher habe ich G_BAg nur in verbindung mit objecten benutzt
-
pstr ist ein zeiger auf einen string und curr liefert dir eine referenz auf einen const-string zurück.
also entwederstring const* pstr; //... pstr = &SlmysCourser.curr(); //oder mit referenz string const& pstr = SlmysCourser.curr(); //geht _nur_ sooder, wenn du lieber kopieren möchtest
string pstr; //... pstr = SlmysCourser.curr(); //bzw. string pstr (SlmysCourser.curr());oder du nimmst den operator* von SlmysCourser und schreibst das ganze einfacher mit
string str = *SlmysCourser; //ist das intuitiv? ich wage fast, das zu bezweifeln...
-
mhh merci, aber jetzt habe ich einen andere fehler:
string const* pstr; G_BAG (string) foundSlmys; G_Cursor <string> SlmysCourser (foundSlmys); Cc_SLMYs entry; //spalte um spalte wird nach der wortkette "FAILED" untersucht while(getline(datei, zeile)) { entry = lineReader(lineNumber); lineNumber++; while(SlmysCourser.next() != NULL) { tempStr = entry.SLMY; pstr = &SlmysCourser.curr(); if(tempStr != pstr) { foundSlmys.add(tempStr); numberSlmy++; } } }fehlermeldung:
Compiling...
Cc_SLMYs.cpp
D:\HTE_WSP\U\VOBS\HTE\CODE\COMMON\CheckWorkloadAnalysetool\AnalyseTool\Cc_SLMYs.cpp(318) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,clas
s std::allocator<char> > *' (or there is no acceptable conversion)
Error executing cl.exe.
Creating browse info file...AnalyseTool.lib - 1 error(s), 0 warning(s)
-
mein vorschlag: lass pstr ganz weg und schreib nur mehr
if(tempStr != SlmysCourser.curr()) { foundSlmys.add(tempStr); numberSlmy++; } }ansonsten müsstest du den zeiger dereferenzieren:
if (tempStr != *pstr)
-
uupps das habe ich übersehen mit dem zeiger, den zweiten vorschlag von dir habe ich eben schon ausprobiert habe imm er diesen fehler:
Compiling...
Cc_SLMYs.cpp
d:\hte_wsp\u\vobs\hte\code\common\generic\include\gop.h(75) : error C2440: 'type cast' : cannot convert from 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'class G_HashValue'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\hte_wsp\u\vobs\hte\code\common\generic\include\gop.h(74) : while compiling class-template member function 'unsigned long __cdecl G_Op<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::hash(const cl
ass std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)'
d:\hte_wsp\u\vobs\hte\code\common\generic\include\gop.h(75) : error C2512: 'G_HashValue' : no appropriate default constructor available
d:\hte_wsp\u\vobs\hte\code\common\generic\include\gop.h(74) : while compiling class-template member function 'unsigned long __cdecl G_Op<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::hash(const cl
ass std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)'
Error executing cl.exe.
Creating browse info file...AnalyseTool.lib - 2 error(s), 0 warning(s)