三星bada开发不使用指针

samsung bada development without using pointers(三星bada开发不使用指针)
本文介绍了三星bada开发不使用指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用下面列出的方法(我知道)创建 C++ 中的对象:

Objects in C++ can be created using the methods listed below(that I am aware of):

Person p;

Person p("foobar");

Person * p = new Person();

那么,为什么三星 Bada IDE 不允许我执行前两种方法?为什么我总是必须使用指针?我可以使用指针等等,只是我想知道样式背后的根本原因.

Then, why does not the Samsung Bada IDE allow me to do the first two methods? Why do I always have to use pointers? I am ok with using pointers and all, just that I want to know the fundamental reason behind the style.

来自 Bada API 参考的示例代码.

Sample code from Bada API reference.

// Create a Label
Label *pLabel = new Label();
pLabel->Construct(Rectangle(50, 200, 150, 40), L"Text");
pLabel->SetBackgroundColor(Color::COLOR_BLUE);
AddControl(*pLabel);

我修改并尝试使用下面的代码.虽然它编译并且应用程序运行,但标签不会显示在表单上.

I modified and tried using the code below. Although it compiles and the app runs, the label does not show up on the form.

// Create a Label
Label pLabel();
pLabel.Construct(Rectangle(50, 200, 150, 40), L"Text");
pLabel.SetBackgroundColor(Color::COLOR_BLUE);
AddControl(pLabel);

注意:使用的 Rectangle 类在没有指针的情况下动态创建对象.那么它与Label有什么不同呢?它令人困惑:-/

Note : Rectangle class which is used creates an object on the fly without pointer. How is it different from Label then? Its confusing :-/

推荐答案

在这段代码中:

// Create a Label
Label pLabel;
pLabel.Construct(Rectangle(50, 200, 150, 40), L"Text");
pLabel.SetBackgroundColor(Color::COLOR_BLUE);
AddControl(pLabel);

标签对象在超出范围时被销毁,因此无法显示在表单上.不幸的是, AddControl 方法需要一个引用,因为这意味着上面应该可以工作.使用:

the label object is destroyed when it goes out of scope and hence it fails to show up on the form. It is unfortunate that the AddControl method takes a reference as that implies that the above should work. Using:

Label *pLabel = new Label();

因为当 pLabel 变量超出范围时默认不调用析构函数.

works because the destructor is not called by default when the pLabel variable goes out of scope.

这篇关于三星bada开发不使用指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)