fehler beim zurückgeben einer map
-
hallo!
ich habe eine funktion, in der eine std::map<double, int> zurückgegeben werden soll. diese steht in egomotion.cpp :
std::map<double, int> createMap() { std::map<double, int> m; //füllen der map return m; }die funktion wird im header-file egomotion.h definiert:
std::map<double, int> createMap();wenn ich den code zu compilieren versuche bekomme ich eine ganze latte von fehlern. (ich paste die gleich unten mal rein). das seltsame ist, dass sobald ich als return-typ für die funktion anstatt "std::map<double, int>" "void" wähle, der code problemlos compiliert.
ich bin noch blutiger anfänger in c++ und überlege und probiere schon geraume zeit herum. es wäre toll, wenn mir das jemand erklären könnte.
viele dank schonmal!!
das hier ist die fehlermeldung, die ich bekomme (programmiere unter ms visual studio 2005):
1>------ Build started: Project: OpticFlow, Configuration: Release Win32 ------ 1>Compiling... 1>OpticFlow.cpp 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C2039: 'map' : is not a member of 'std' 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C2143: syntax error : missing ';' before '<' 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>.\OpticFlow.cpp(107) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(107) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(107) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(107) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(156) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(156) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(156) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(156) : warning C4244: 'argument' : conversion from 'ImgFloat' to 'int', possible loss of data 1>.\OpticFlow.cpp(170) : error C3861: 'createHistogramm': identifier not found 1>egomotion.cpp 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C2039: 'map' : is not a member of 'std' 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C2143: syntax error : missing ';' before '<' 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>.\egomotion.cpp(175) : warning C4244: '+=' : conversion from 'double' to 'float', possible loss of data 1>.\egomotion.cpp(177) : warning C4244: '+=' : conversion from 'mtFloat' to 'float', possible loss of data 1>.\egomotion.cpp(571) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data 1>.\egomotion.cpp(646) : error C2872: 'map' : ambiguous symbol 1> could be 'c:\projekt\opticflow\opticflow\egomotion.h(84) : int map' 1> or 'C:\Programme\Microsoft Visual Studio 8\VC\include\map(81) : std::map' 1>.\egomotion.cpp(646) : error C2872: 'map' : ambiguous symbol 1> could be 'c:\projekt\opticflow\opticflow\egomotion.h(84) : int map' 1> or 'C:\Programme\Microsoft Visual Studio 8\VC\include\map(81) : std::map' 1>.\egomotion.cpp(646) : error C2872: 'map' : ambiguous symbol 1> could be 'c:\projekt\opticflow\opticflow\egomotion.h(84) : int map' 1> or 'C:\Programme\Microsoft Visual Studio 8\VC\include\map(81) : std::map' 1>.\egomotion.cpp(646) : error C2872: 'map' : ambiguous symbol 1> could be 'c:\projekt\opticflow\opticflow\egomotion.h(84) : int map' 1> or 'C:\Programme\Microsoft Visual Studio 8\VC\include\map(81) : std::map' 1>.\egomotion.cpp(646) : error C2062: type 'double' unexpected 1>.\egomotion.cpp(646) : error C2039: 'const_iterator' : is not a member of '`global namespace'' 1>.\egomotion.cpp(646) : error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'std::_Tree<_Traits>::iterator' (or there is no acceptable conversion) 1> with 1> [ 1> _Traits=std::_Tmap_traits<double,int,std::less<double>,std::allocator<std::pair<const double,int>>,false> 1> ] 1> C:\Programme\Microsoft Visual Studio 8\VC\include\vector(201): could be 'bool std::_Vector_const_iterator<_Ty,_Alloc>::operator !=(const std::_Vector_const_iterator<_Ty,_Alloc> &) const' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1> while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>, std::_Tree<_Traits>::iterator)' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1> and 1> [ 1> _Traits=std::_Tmap_traits<double,int,std::less<double>,std::allocator<std::pair<const double,int>>,false> 1> ] 1>.\egomotion.cpp(646) : error C2143: syntax error : missing ';' before ')' 1>.\egomotion.cpp(646) : error C2143: syntax error : missing ';' before ')' 1>.\egomotion.cpp(647) : error C2143: syntax error : missing ';' before '{' 1>.\egomotion.cpp(648) : error C2839: invalid return type 'int *' for overloaded 'operator ->' 1>.\egomotion.cpp(648) : error C2039: 'first' : is not a member of 'std::_Vector_iterator<_Ty,_Alloc>' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1>.\egomotion.cpp(648) : error C2839: invalid return type 'int *' for overloaded 'operator ->' 1>.\egomotion.cpp(648) : error C2039: 'second' : is not a member of 'std::_Vector_iterator<_Ty,_Alloc>' 1> with 1> [ 1> _Ty=int, 1> _Alloc=std::allocator<int> 1> ] 1>Build log was saved at "file://c:\Projekt\OpticFlow\OpticFlow\Release\BuildLog.htm" 1>OpticFlow - 21 error(s), 11 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Du hast das "Füllen der Map" auskommentiert, zeig uns mal den kompletten Code, laut Fehlermeldungen, scheint der Fehler darin zu liegen.
-
lotte schrieb:
1>------ Build started: Project: OpticFlow, Configuration: Release Win32 ------ 1>Compiling... 1>OpticFlow.cpp 1>c:\projekt\opticflow\opticflow\egomotion.h(84) : error C2039: 'map' : is not a member of 'std'#include <map> wäre schonmal ein anfang
-
hallo firefighter!
das is die vollständige funktion:
std::map<double, int> createMap(SphericalFlowField * SFF, std::vector<int> * op_set) { vector<int>::iterator it; std::map<double, int> m; double temp; for (it = op_set->begin(); it != op_set->end(); it++) { temp = round(SFF->quality[*it],4); m[temp]++; } int i=0; for(map<double, int>::const_iterator it = m.begin(); it != m.end(); ++it) { i++; } return m; }
-
Firefighter schrieb:
Du hast das "Füllen der Map" auskommentiert, zeig uns mal den kompletten Code, laut Fehlermeldungen, scheint der Fehler darin zu liegen.
Die Fehlermeldungen scheinen mir ziemlich klar zu sein, dass es nicht nur ein Fehler ist

Wenn da "map is not a member of std" steht, dann hat er wohl vergessen
#include <map>hinzuschreiben.
Dann hat er anscheinend eine Variable definiert, welche sich mit einem Typ überlagert.
Er benutzt den const_iterator falsch oder der Compiler hat die map nicht erkannt und such den const_iterator global.
Dann probiert er anscheinend einen Tree-Iterator mit einem Vector-Iterator zu vergleichen.
Dann fehlen einige Semikolons.
Er hat einen falschen Rückgabewert.
Und er versucht auf einen Vector-Iterator wie auf einen Map-Iterator zuzugreifen.Zudem jede Menge an Warnings wegen Verlust von Daten durch Datenkonvertierung.
Also am besten, zeigst du mal den Ganzen Code von "egomotion.h" und "egomotion.cpp".
Grüssli
-
der heldenhafte jemand (ich) hat tatsächlich in der .h-datei vergessen map zu includieren. aaaarrrgh!!
herzlichen dank euch allen!
werde das das nächste mal (hoffentlich!) als erstes überprüfen!!!