本文介绍了在构建之间更改sizeof(std :: vector)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将指针导出到包含私有std :: vector成员的类的实例.出于某种原因,私有向量成员在DLL中的构造与从DLL的客户端访问对象之间的某个时间变得损坏.我将问题缩小到以下范围:

I am attempting to export a pointer to an instance of a class that contains a private std::vector member. For some reason, the private vector member is becoming corrupted sometime between construction within the DLL and accessing the object from a client of the DLL. I have narrowed down the problem to the following:

#include <vector>
using namespace std;

size_t const A(sizeof(size_t));
size_t const B(sizeof(myType));
size_t const C(sizeof(vector<myType>));
size_t const D(sizeof(vector<myType>::size_type));


在上面的代码中,DLL和客户端中的A == 8,B == 40和D == 8.但是,在DLL中,C == 40,而在客户端中,C == 32.这怎么可能?有什么区别?有没有一种方法可以强制内置向量类型在两个版本之间保持一致,还是我必须编写自己的容器类?感谢您的帮助,

-Jeff


In the above code, A==8, B==40, and D==8 in both the DLL and the client. However, in the DLL C==40, but in the client C==32. How is this possible? What could be the difference? Is there a way to force the built-in vector type to be consistent between the two builds, or do I have to write my own container class? Thanks for any help,

-Jeff

推荐答案


这篇关于在构建之间更改sizeof(std :: vector)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:37
查看更多