可以使用下面列出的方法(我知道)创建 C++ 中的对象:
Person p;
或者
Person p("foobar");
或者
Person * p = new Person();
那么,为什么三星 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有什么不同呢?它令人困惑:-/