【发布时间】:2011-06-08 08:42:18
【问题描述】:
我在 C++ 中有一个函数,例如:
void* getField(interface* p)
{
int* temp = new int( p->intValue);
cout<< "pointer value in c++" << temp << "value of temp = " << temp << endl;
return temp;
}
我正在使用 SWIG 为上述类生成包装器。现在我试图在 Perl 中获取返回的指针值。我该怎么做??
我编写了以下 perl 脚本来调用该函数:
perl
use module;
$a = module::create_new_interface();
$b = module::getField();
print $b,"\n";
print $$b, "\n";
我已经正确定义了 create_interface 函数,因为在调用函数 getField() 时会打印接口的正确 intValue。
程序的输出如下:
_p_void=SCALAR(0x5271b0)
5970832
pointer value in c++ 0x5b1b90 value of temp 22
为什么这两个值——C++ 中的指针和 perl 中的引用不同?我如何从参考中获取 intValue? (即值 22 )
【问题讨论】: