三星bada开发不使用指针
C++ 中的对象可以使用下面列出的方法创建(据我所知):
Person p;
or
Person p("foobar");
or
Person * p = new Person();
那么,为什么 Samsung Bada IDE 不允许我执行前两种方法?为什么我总是必须使用指针?我可以使用指针等,只是我想知道这种风格背后的根本原因。
来自 Bada API 参考的示例代码。
// Create a Label
Label *pLabel = new Label();
pLabel->Construct(Rectangle(50, 200, 150, 40), L"Text");
pLabel->SetBackgroundColor(Color::COLOR_BLUE);
AddControl(*pLabel);
我修改并尝试使用下面的代码。尽管它可以编译并且应用程序可以运行,但标签不会显示在表单上。
// Create a Label
Label pLabel();
pLabel.Construct(Rectangle(50, 200, 150, 40), L"Text");
pLabel.SetBackgroundColor(Color::COLOR_BLUE);
AddControl(pLabel);
注意:使用的 Rectangle 类在没有指针的情况下动态创建对象。那么它和Label有什么不同呢?它令人困惑:-/
Objects in C++ can be created using the methods listed below(that I am aware of):
Person p;
or
Person p("foobar");
or
Person * p = new Person();
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.
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);
Note : Rectangle class which is used creates an object on the fly without pointer. How is it different from Label then? Its confusing :-/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在此代码中:
标签对象在超出范围时被销毁,因此无法显示在表单上。不幸的是,
AddControl
方法需要一个引用,因为这意味着上面的方法应该可以工作。使用:之所以有效,是因为当
pLabel
变量超出范围时,默认情况下不会调用析构函数。In this code:
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:works because the destructor is not called by default when the
pLabel
variable goes out of scope.请注意 Bada文档是这么说的
您的代码可能运行良好,因为它会忽略对 AddControl 的调用,因为它检测到该控件未在堆空间中分配。在这种情况下,AddControl 应该返回一个错误代码。
要获得正确的 Bada 代码,需要编写如下内容:
}
遵循此类编码指南可确保您的应用程序能够在初始化 UI 时升级任何问题,除非在执行 OnAppInitializing 时发生问题。
Note that Bada documentation says this
Your code may run fine because it ignores the call to AddControl because it detected that the control was not allocated in the heap space. In that case AddControl should have returned an error code.
To get a correct Bada code, one needs to write something like:
}
Following such coding guidelines ensures that your application will be able to escalate any issues while initializing UI except if the issue happens whiele executing OnAppInitializing.
访客在他的评论中指出了这一点; Bada 使用 Symbian 在九十年代中期首创的 C++ 技术。今天它们已经完全过时了。别太认真了,你真的不能指望三星会把他们的顶级人才投入到这样一个注定失败的项目中。这些将在他们的 Android 系列上运行。
Visitor nailed it in his comment; Bada uses C++ techniques pioneered in the mid-nineties by Symbian. They're utterly outdated today. Don't take it too seriously, you can't really expect Samsung to put their top-rate people on such a doomed project. Those will be working on their Android line.