如何初始化库指针

如何初始化库指针

本文介绍了如何初始化库指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 使用Visual Studio 2015社区版。 我在库中实例化了一个全局对象。该对象包含一个字符串向量。除了在以下条件下,正确访问和使用该全局对象没有问题。 如果库中没有应用程序代码的一部分抛出异常,则异常处理调用进入该对象,访问字符串向量以进行报告。 catch (例外& e){ dwl :: Globals * p = gDwlGlobals; // 测试是否以这种方式访问​​gDwlGlobals修复它。 wStringStream s; // 对于调试,只是为了查看地址是否与之前相同 s<< ;磷; // 打印地址以调试输出的快捷方式 OutputDebugString(s.str()。 c_str()); const 字符串& strings = gDwlGlobals-> strings(); // 参见A. wString str = strings [Strings :: Error_Programming]; // 参见B. ... OutputDebugString 为实例化时全局显示的全局地址提供相同的地址。 At(* A *) - 在调试器中,全局地址在此行上正确显示,'字符串'向量通过下拉列表显示其中的79个元素。 At(* B *) - 字符串向量现在为空!并且枚举偏移量会在我的异常中引发异常。 任何指针? 我尝试了什么: 我能想到的一切除了消除库方法和看看使解决方案成为一个项目修复它。 (我认为它会修复它,因为我不记得在将它拆分成库之前发生的这个错误。但是我想知道为什么这不起作用。) 好​​的,我只是试图消除lib方法。怀疑,错误消失了。因此,问题必须是 extern 定义在库和非库代码中的某种程度上是不一样的,即使只有一个真正的非外部定义。关于将lib指针同步到主应用程序的任何指针?解决方案 Using Visual Studio 2015 Community Edition.I have a global object instantiated in a library. That object contains a vector of strings. That global object is accessed and used correctly without problems except under the following condition.If a portion of application code not in the library throws an exception, the exception processing calls into that object, to access the vector of strings for reporting purposes.catch (Exception & e) { dwl::Globals * p = gDwlGlobals; //Test to see if accessing gDwlGlobals this way fixes it. wStringStream s; //For debugging, just to see if the address is same as previous s << p; //quick way to print address to debug output OutputDebugString(s.str().c_str()); const Strings & strings = gDwlGlobals->strings(); //See A. wString str = strings[Strings::Error_Programming]; //See B. ...The OutputDebugString gives the same address for the global as the global showed during instantiation.At (*A*) - In the debugger, the global address shows correctly on this line, and the 'strings' vector shows 79 elements in it through the dropdowns.At (*B*) - The strings vector is now empty! And the enum offset throws an exception in my exception.Any pointers?What I have tried:Everything I can think of except eliminating the library approach and seeing if making the solution into one project fixes it. (I think it will fix it, because I don't remember this error occurring before splitting it apart into a library. But I'd like to know why this isn't working.)OK, I just tried eliminating the lib approach. As suspected, the error goes away. So the problem must be that the extern definitions are somehow not the same in the library and the non-library code, even though there is only one true non-extern definition. Any pointers on syncing lib pointers to the main application? 解决方案 这篇关于如何初始化库指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 16:54