简体   繁体   English

Gloox XMPP库,EXC_BAD_ACCESS

[英]Gloox XMPP library, EXC_BAD_ACCESS

I'm attempting to code a basic XMPP client with the gloox C++ library. 我正在尝试使用gloox C ++库编写基本的XMPP客户端。 It's my first time using C++ but gloox sounded the most appropriate for my needs and I've got both C and OO experience so I wasn't too worried about trying it. 这是我第一次使用C ++,但是gloox听起来最适合我的需求,并且我有C和OO的经验,所以我不太担心尝试它。

I have however run into a wall from the start. 但是我从一开始就碰壁了。 I can't even get a "hello world" out of my code, instead getting an EXC_BAD_ACCESS error (using Xcode 4). 我什至无法从代码中获得“ hello world”,而是得到EXC_BAD_ACCESS错误(使用Xcode 4)。

http://pastebin.com/7vS6ExUV http://pastebin.com/7vS6ExUV

Here's the code, it crashes on line 35. Gloox mailing list is pretty quite so I thought I'd ask here. 这是代码,它在第35行崩溃。Gloox邮件列表相当不错,所以我想在这里询问。 Bit worrying there is no gloox tag though! 有点担心,虽然没有gloox标签!

I'm a little rusty on the old C++ myself, but your main method doesn't look right to me. 我本人对旧的C ++有点生锈,但是您的主要方法对我而言并不正确。 On line 49 you declare a pointer to an instance of MyClass, but don't allocate it. 在第49行,您声明一个指向MyClass实例的指针,但不分配它。 So you're calling doIt() on at best a null pointer, at worst an garbage object in some random memory space. 因此,您最多在空指针上调用doIt(),最坏的情况是在某些随机存储空间中调用垃圾对象。

Either create a new instance or just drop the pointer. 创建一个新实例或只是删除指针。 eg: 例如:

int main( int argc, char* argv[] ){
   MyClass a; // note, no pointer
   a->doIt();
   return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM