Apple GCC 4.2.1将指针传递给构造函数
Apple GCC 4.2.1 passing a pointer to constructor
假设我有一个类,它或它的成员没有明显的问题,但是如果我试图将几个类成员的地址传递给同一模块中的另一个类,第一个参数被正确传递,但第二个参数总是NULL!这怎么可能呢?是否存在某种隐藏的堆栈/堆损坏或某种对齐问题?MSVC没有问题,但是…
class myType2
{
char c1;
char c2;
} __attribute__ ((aligned (1))); // Yes, align differs and I can't change it
class MyClass2
{
public:
MyClass2(myType1* type1, myType2* type2, int data)
{
// type1 and data are ok, but type2 is NULL...
}
} __attribute__ ((aligned (16)));
class MyClass
{
public:
myType1 type1;
myType2 type2;
//....
void test()
{
MyClass2 test1(&this->type1, &this->type2, 170);
MyClass2* pTest2 = new MyClass2(&this->type1, &this->type2, 170); // Same result
myType2 localType2;
MyClass2 test3(&this->type1, &localType2, 170); // Same result!!!
}
} __attribute__ ((aligned (16)));
该死的GCC…我不能正常解决这个问题,但我找到了一个解决办法,通过传递所有类构造函数数据在一个16字节边界对齐的结构。
相关文章:
- 如果基类包含双指针成员,则派生类的构造函数
- 复制构造函数C++无法正确复制指针
- 使用基类指针调用基类的值构造函数的语法是什么?
- C++ 对象指针数组的复制构造函数
- 构造函数 (C++) 中的 char 指针参数存在问题
- 为什么使用 std::istream_iterator 构造函数返回指针
- 在对象构造期间,将指向尚未构造的子对象的指针传递给另一个子对象的构造函数是否危险?
- 使用指向成员函数的指针在另一个类中调用类构造函数
- 通过从构造函数中的'this'复制的指针改变常量对象
- 为什么指针对象没有调用默认构造函数
- 函数返回时,带指针的复制构造函数失败
- 如何编写复制构造函数来复制指针?
- 如何使用函数(而不是构造函数)将派生类对象分配给基类指针
- 使用 Rcpp 公开将指向对象的指针作为参数的构造函数
- std::shared_ptr 使用别名构造函数,是否可以检索初始指针值?
- 如何正确实现具有原始指针的类的复制构造函数?
- 构造函数主体内的本地指针C++内存泄漏
- 如何在将原始指针移动到基类构造函数之前从unique_ptr中提取原始指针
- 有没有办法通过读取 c++ 中的文件来构造函数指针
- 构造函数指针改变