<legend id='qPUq0'><style id='qPUq0'><dir id='qPUq0'><q id='qPUq0'></q></dir></style></legend>

    1. <i id='qPUq0'><tr id='qPUq0'><dt id='qPUq0'><q id='qPUq0'><span id='qPUq0'><b id='qPUq0'><form id='qPUq0'><ins id='qPUq0'></ins><ul id='qPUq0'></ul><sub id='qPUq0'></sub></form><legend id='qPUq0'></legend><bdo id='qPUq0'><pre id='qPUq0'><center id='qPUq0'></center></pre></bdo></b><th id='qPUq0'></th></span></q></dt></tr></i><div id='qPUq0'><tfoot id='qPUq0'></tfoot><dl id='qPUq0'><fieldset id='qPUq0'></fieldset></dl></div>

      <small id='qPUq0'></small><noframes id='qPUq0'>

      <tfoot id='qPUq0'></tfoot>
        <bdo id='qPUq0'></bdo><ul id='qPUq0'></ul>
      1. C++“致命错误LNK1120"未解析的静态类成员

        C++ quot;fatal error LNK1120quot; unresolved static class members(C++“致命错误LNK1120未解析的静态类成员)

        • <i id='EjIRG'><tr id='EjIRG'><dt id='EjIRG'><q id='EjIRG'><span id='EjIRG'><b id='EjIRG'><form id='EjIRG'><ins id='EjIRG'></ins><ul id='EjIRG'></ul><sub id='EjIRG'></sub></form><legend id='EjIRG'></legend><bdo id='EjIRG'><pre id='EjIRG'><center id='EjIRG'></center></pre></bdo></b><th id='EjIRG'></th></span></q></dt></tr></i><div id='EjIRG'><tfoot id='EjIRG'></tfoot><dl id='EjIRG'><fieldset id='EjIRG'></fieldset></dl></div>
          • <small id='EjIRG'></small><noframes id='EjIRG'>

              <tfoot id='EjIRG'></tfoot>
                <tbody id='EjIRG'></tbody>
              <legend id='EjIRG'><style id='EjIRG'><dir id='EjIRG'><q id='EjIRG'></q></dir></style></legend>

                • <bdo id='EjIRG'></bdo><ul id='EjIRG'></ul>
                  本文介绍了C++“致命错误LNK1120"未解析的静态类成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我收到以下错误消息(有人可以随意编辑不必要的位):

                  I get the following error message (someone feel free to edit the unnecessary bits):

                  1>FIXDecoder.obj:错误 LNK2001:未解析的外部符号私有:静态类 std::unordered_map,class std::allocator >,classstd::basic_string, 类std::allocator >,struct std::hash,classstd::allocator > >,struct std::equal_to,classstd::allocator > >,class std::allocator,classstd::allocator > const ,类 std::basic_string,类 std::allocator > > > >FD::FixValueMappingsDict"(?FixValueMappingsDict@FD@@0V?$unordered_map@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@U?$hash@V?$basic_string@DU?$char_traits@D@V?$allocator@D@U?$equal_to@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@@@A)

                  1>FIXDecoder.obj : error LNK2001: unresolved external symbol "private: static class std::unordered_map,class std::allocator >,class std::basic_string,class std::allocator >,struct std::hash,class std::allocator > >,struct std::equal_to,class std::allocator > >,class std::allocator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > FD::FixValueMappingsDict" (?FixValueMappingsDict@FD@@0V?$unordered_map@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@U?$hash@V?$basic_string@DU?$char_traits@D@V?$allocator@D@U?$equal_to@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@@@A)

                  1>FD.obj : error LNK2001: 未解析的外部符号private: static类 std::unordered_map, 类 std::allocator >, 类std::basic_string, 类std::allocator >,struct std::hash,classstd::allocator > >,struct std::equal_to,classstd::allocator > >,class std::allocator,classstd::allocator > const ,类 std::basic_string,类 std::allocator > > > >FD::FIXFieldNoDict"(?FIXFieldNoDict@FD@@0V?$unordered_map@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@U?$hash@V?$basic_string@DU?$char_traits@D@V?$allocator@D@U?$equal_to@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@@@A)

                  1>FD.obj : error LNK2001: unresolved external symbol "private: static class std::unordered_map,class std::allocator >,class std::basic_string,class std::allocator >,struct std::hash,class std::allocator > >,struct std::equal_to,class std::allocator > >,class std::allocator,class std::allocator > const ,class std::basic_string,class std::allocator > > > > FD::FIXFieldNoDict" (?FIXFieldNoDict@FD@@0V?$unordered_map@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@U?$hash@V?$basic_string@DU?$char_traits@D@V?$allocator@D@U?$equal_to@V?$basic_string@DU?$char_traits@D@V?$allocator@D@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@V?$allocator@D@V12@@@A)

                  1>C:visual studio 2012ProjectsFDx64DebugFD.exe:致命错误LNK1120:2 个未解析的外部

                  1>C:visual studio 2012ProjectsFDx64DebugFD.exe : fatal error LNK1120: 2 unresolved externals

                  对于此代码:

                  //FH.h
                  #ifndef FD_H
                  #define FD_H
                  
                  #include "FM.h"
                  #include <unordered_map>
                  #include <string>
                  
                  class FD{
                  public:
                      FD();
                      FD(FM message);
                      ~FD();
                      FD(const FD& tocopy);
                      FD& operator=(const FD& toassign);
                  
                  private:
                      static unordered_map<string,string> FIXFieldNoDict;
                      static unordered_map<string,string> FixValueMappingsDict;
                  };
                  
                  #endif
                  
                  //FD.cpp
                  #include "FD.h"
                  #include "Mappings.h"
                  #include "Utils.h"
                  #include <vector>
                  #include <string>
                  #include <iostream>
                  #include <unordered_map>
                  
                  using namespace std;
                  
                  FD::FD(){
                      FIXFieldNoDict = Mappings::createFIXFieldNoDict();
                      FixValueMappingsDict = Mappings::getFIXValuesDict();
                  }
                  

                  Mappings.h 只包含一些创建 unordered_map 的函数

                  Mappings.h just contains some functions which create an unordered_map

                  #ifndef MAPPINGS_H
                  #define MAPPINGS_H
                  
                  #include <unordered_map>
                  #include <string>
                  
                  using namespace std;
                  
                  class Mappings{
                  
                  public:
                      Mappings();
                  
                      static unordered_map<string,string> createFIXFieldNoDict();
                  
                      static unordered_map<string,string> getFIXValuesDict();
                  .
                  .
                  };
                  

                  推荐答案

                  您需要在 FD.cpp 文件中创建静态成员的实例:

                  You need to create instances of your static members in the FD.cpp file:

                  //FD.cpp
                  #include "FD.h"
                  #include "Mappings.h"
                  #include "Utils.h"
                  #include <vector>
                  #include <string>
                  #include <iostream>
                  #include <unordered_map>
                  
                  using namespace std;
                  
                  unordered_map<string,string> FD::FIXFieldNoDict = Mappings::createFIXFieldNoDict();
                  unordered_map<string,string> FD::FixValueMappingsDict = Mappings::getFIXValuesDict();
                  
                  
                  FD::FD(){
                  }
                  

                  注意你不应该在 FD 构造函数中初始化它们,因为你可以在构造任何对象之前使用静态成员(并且你需要初始化它们一次而不是每次当某个对象被构造).

                  Note that you shouldn't initialize them in the FD constructor, as you can use static members before construction of any object (and you need to initialize them once and not every time when some object is constructed).

                  这篇关于C++“致命错误LNK1120"未解析的静态类成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)
                  • <bdo id='2oQ5d'></bdo><ul id='2oQ5d'></ul>

                      <small id='2oQ5d'></small><noframes id='2oQ5d'>

                            <tbody id='2oQ5d'></tbody>
                        • <i id='2oQ5d'><tr id='2oQ5d'><dt id='2oQ5d'><q id='2oQ5d'><span id='2oQ5d'><b id='2oQ5d'><form id='2oQ5d'><ins id='2oQ5d'></ins><ul id='2oQ5d'></ul><sub id='2oQ5d'></sub></form><legend id='2oQ5d'></legend><bdo id='2oQ5d'><pre id='2oQ5d'><center id='2oQ5d'></center></pre></bdo></b><th id='2oQ5d'></th></span></q></dt></tr></i><div id='2oQ5d'><tfoot id='2oQ5d'></tfoot><dl id='2oQ5d'><fieldset id='2oQ5d'></fieldset></dl></div>

                          <legend id='2oQ5d'><style id='2oQ5d'><dir id='2oQ5d'><q id='2oQ5d'></q></dir></style></legend>

                        • <tfoot id='2oQ5d'></tfoot>