STL - 以下代码有什么问题?

q09*_*987 5 c++ stl

#include "stdafx.h"
#include <string>
#include <map>
using namespace std;

class NiftyEmailProgram {
private:
    typedef map<string, string> NicknameMap;
    NicknameMap nicknames;

public:
    void ShowEmailAddress(const string& nickname) const
    {
        NicknameMap::const_iterator i = nicknames.find(nickname);

        if ( i != nicknames.end() )
        {
        }
    }

};

int main(int argc, char* argv[])
{
    printf("Hello World!\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我在VC6.0中编译上面的代码时,我看到了大量的警告.如果我使用警告级别4并将所有警告视为错误,则STLFilt的输出错误如下:

Compiling...
t3.cpp
c:\devstudio_6.0\vc98\include\xtree(118): error C2220: warning treated as error - no object file generated
    c:\devstudio_6.0\vc98\include\map(46): see reference to class template instantiation 'map<string,string>' being compiled
    C:\TEMP\t3\t3.cpp(12): see reference to class template instantiation 'map<string,string>' being compiled
Error executing cl.exe.  


t3.exe - 1 error(s), 26 warning(s)
Tool returned code: 0
Run Code Online (Sandbox Code Playgroud)

现在,这段代码的问题是什么,我该如何解决?

谢谢

Mat*_*lia 3

尝试发布未处理的警告。

However, I too remember that I got some level 4 warning from <xtree> in <map> , that could be safely ignored (IIRC it was C4702, which is harmless).

To avoid the warning, I put around the STL #includes some appropriate #pragma warning directives (enclosed in the correct #ifdefs to have them considered only on MSVC++, thanks to @Alexandre C. for reminding me of it):

#ifdef _MSC_VER
    //Disable the C4702 warning for the following headers
    #pragma warning(push)
    #pragma warning(disable:4702)
#endif // _MSC_VER
//map STL container
#include <map>
//list STL container
#include <list>
//vector STL container
#include <vector>
#ifdef _MSC_VER
    #pragma warning(pop)
#endif
Run Code Online (Sandbox Code Playgroud)

You could also simply lower the warning level to 3 (or even lower) just in that section with:

#ifdef _MSC_VER
    // Lower the warning level to 3 just for this section
    #pragma warning(push, 3)
#endif
//map STL container
#include <map>
//list STL container
#include <list>
//vector STL container
#include <vector>
#ifdef _MSC_VER
    #pragma warning(pop)
#endif // _MSC_VER
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅文档#pragma warning.