从命令提示符编译 BADA 简单的 helloworld 程序并出现错误

发布于 2024-09-16 05:32:49 字数 5128 浏览 3 评论 0原文

我试图为 BADA 编译一个简单的 Helloworld 程序,但通过命令提示符。编译后我收到错误如下 c:/Helloworld/src/Helloworld.cpp:12:错误:“Osp::App::Application HelloWorld::CreateInstance()”的原型与“HelloWorld”类中的任何内容都不匹配 C:/Helloworld/inc/HelloWorld.h:21:错误:候选者是:静态 Osp::App::Application* HelloWorld::CreateInstance() 任何机构都可以帮助解决需要做的事情吗? 感谢

Helloworld.h 代码

#ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__

#include <FBase.h>
#include <FGraphics.h>
#include <FLocales.h>
#include <FSystem.h>
#include <FApp.h>

using namespace Osp::Base;
using namespace Osp::Graphics;
using namespace Osp::Locales;
using namespace Osp::System;
using namespace Osp::App;

class HelloWorld :
    public Application // must inherit from Application class
{
public:
    // The application must have a factory method that creates an instance of the application.
    static Application* CreateInstance(void);

public:
    HelloWorld();
    ~HelloWorld();

public:
       // The application must provide its name.
    String GetAppName(void) const;

protected:
    // The application must provide its ID.
    AppId GetAppId(void) const;

    AppSecret GetAppSecret(void) const;

public:
    // This method is called when the application is initializing.
    bool OnAppInitializing(AppRegistry& appRegistry);

    // This method is called when the application is terminating.
    bool OnAppTerminating(AppRegistry& appRegistry);

    // Thie method is called when the application is brought to the foreground
    void OnForeground(void);

    // This method is called when the application is sent to the background.
    void OnBackground(void);

    // This method is called when the application has little available memory.
    void OnLowMemory(void);

    // This method is called when the device's battery level changes.
    void OnBatteryLevelChanged(BatteryLevel batteryLevel);
};

#endif

Helloworld.cpp 代码

#include "HelloWorld.h"

HelloWorld::HelloWorld()
{
}

HelloWorld::~HelloWorld()
{
}

Application*
HelloWorld::CreateInstance(void)
{
    // You can create the instance through another constructor.
    return new HelloWorld();
}

String
HelloWorld::GetAppName(void) const
{
    static String appName(L"HelloWorld");
    return appName;
}

AppId
HelloWorld::GetAppId(void) const
{
    static AppId appId(L"93bt1p123e");
    return appId;
}

AppSecret
HelloWorld::GetAppSecret(void) const
{
    static AppSecret appSecret(L"9C645DDBA19C71BAD1204DA4DAA7A0B9");
    return appSecret;
}

bool
HelloWorld::OnAppInitializing(AppRegistry& appRegistry)
{
    // TODO:
    // Initialization including UI construction can be done here.
    // Load the application's latest data, if necessary.
    // If this method is successful, return true; otherwise, return false.
    return true;
}

bool
HelloWorld::OnAppTerminating(AppRegistry& appRegistry)
{
    // TODO:
    // Deallocate or close any resources still alive.
    // Save the application's current states, if applicable.
    // If this method is successful, return true; otherwise, return false.
    return true;
}

void
HelloWorld::OnForeground(void)
{
    result r = E_SUCCESS;

    Canvas* pCanvas = GetAppFrame()->GetCanvasN();
    if(pCanvas == null)
        return;

    Font* pFont = new Font();
 pFont->Construct(FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 50);
    pCanvas->SetFont(*pFont);

    r = pCanvas->DrawText(Point(30, 30), GetAppName());
    if (IsFailed(r))
    {
        AppLog("pCanvas->DrawText() failed.\n");
        delete pCanvas;
        return;
    }

    r = pCanvas->Show();
    if (IsFailed(r))
    {           AppLog("pCanvas->Show() failed.\n");
        delete pCanvas;
        return;
    }

    delete pCanvas;

}

void
HelloWorld::OnBackground(void)
{
}

void
HelloWorld::OnLowMemory(void)
{
    // TODO:
    // Deallocate as many resources as possible.
}

void
HelloWorld::OnBatteryLevelChanged(BatteryLevel batteryLevel)
{
    // TODO:
    // It is recommended that the application save its data,
    // and terminate itself if the application consumes much battery
}

Helloworldentry.cpp 代码

/**
* OSP Application entry point(OspMain) introduced.
*/
#include <fapp.h>
#include "HelloWorld.h"

using namespace Osp::Base::Collection;

extern "C"
{
    __declspec(dllexport) void OspMain(int hInstance, int argc, char *argv[]);
}

/**
* Entry function of OSP Application which is called by the operating system.
*/
extern "C" {
void OspMain(int hInstance, int argc, char *argv[])
{
    AppLog("OspMain() Started. \n");

    result r = E_SUCCESS;

    ArrayList* pArgs = new ArrayList();
    pArgs->Construct();
    for (int i = 0; i < argc; i++)
    {
        String* pEachArg = new String(argv[i]);
        pArgs->Add(*pEachArg);
    }

    r = Osp::App::Application::Execute(HelloWorld::CreateInstance, pArgs);
    if (IsFailed(r))
    {
        AppLog("Application execution has failed.\n");
    }

    if (pArgs)
    {
        pArgs->RemoveAll(true);
        delete pArgs;
    }

    AppLog("OspMain() Ended. \n");
}
}

I was trying to compile a simple Helloworld program for BADA but through command prompt.After compiling i ma getting the errors as
c:/Helloworld/src/Helloworld.cpp:12: error: prototype for 'Osp::App::Application HelloWorld::CreateInstance()' does not match any in class 'HelloWorld'
C:/Helloworld/inc/HelloWorld.h:21: error: candidate is: static Osp::App::Application* HelloWorld::CreateInstance()
could any body help that what needs to be done with it.
Thanks

Code for Helloworld.h

#ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__

#include <FBase.h>
#include <FGraphics.h>
#include <FLocales.h>
#include <FSystem.h>
#include <FApp.h>

using namespace Osp::Base;
using namespace Osp::Graphics;
using namespace Osp::Locales;
using namespace Osp::System;
using namespace Osp::App;

class HelloWorld :
    public Application // must inherit from Application class
{
public:
    // The application must have a factory method that creates an instance of the application.
    static Application* CreateInstance(void);

public:
    HelloWorld();
    ~HelloWorld();

public:
       // The application must provide its name.
    String GetAppName(void) const;

protected:
    // The application must provide its ID.
    AppId GetAppId(void) const;

    AppSecret GetAppSecret(void) const;

public:
    // This method is called when the application is initializing.
    bool OnAppInitializing(AppRegistry& appRegistry);

    // This method is called when the application is terminating.
    bool OnAppTerminating(AppRegistry& appRegistry);

    // Thie method is called when the application is brought to the foreground
    void OnForeground(void);

    // This method is called when the application is sent to the background.
    void OnBackground(void);

    // This method is called when the application has little available memory.
    void OnLowMemory(void);

    // This method is called when the device's battery level changes.
    void OnBatteryLevelChanged(BatteryLevel batteryLevel);
};

#endif

Code for Helloworld.cpp

#include "HelloWorld.h"

HelloWorld::HelloWorld()
{
}

HelloWorld::~HelloWorld()
{
}

Application*
HelloWorld::CreateInstance(void)
{
    // You can create the instance through another constructor.
    return new HelloWorld();
}

String
HelloWorld::GetAppName(void) const
{
    static String appName(L"HelloWorld");
    return appName;
}

AppId
HelloWorld::GetAppId(void) const
{
    static AppId appId(L"93bt1p123e");
    return appId;
}

AppSecret
HelloWorld::GetAppSecret(void) const
{
    static AppSecret appSecret(L"9C645DDBA19C71BAD1204DA4DAA7A0B9");
    return appSecret;
}

bool
HelloWorld::OnAppInitializing(AppRegistry& appRegistry)
{
    // TODO:
    // Initialization including UI construction can be done here.
    // Load the application's latest data, if necessary.
    // If this method is successful, return true; otherwise, return false.
    return true;
}

bool
HelloWorld::OnAppTerminating(AppRegistry& appRegistry)
{
    // TODO:
    // Deallocate or close any resources still alive.
    // Save the application's current states, if applicable.
    // If this method is successful, return true; otherwise, return false.
    return true;
}

void
HelloWorld::OnForeground(void)
{
    result r = E_SUCCESS;

    Canvas* pCanvas = GetAppFrame()->GetCanvasN();
    if(pCanvas == null)
        return;

    Font* pFont = new Font();
 pFont->Construct(FONT_STYLE_PLAIN | FONT_STYLE_BOLD, 50);
    pCanvas->SetFont(*pFont);

    r = pCanvas->DrawText(Point(30, 30), GetAppName());
    if (IsFailed(r))
    {
        AppLog("pCanvas->DrawText() failed.\n");
        delete pCanvas;
        return;
    }

    r = pCanvas->Show();
    if (IsFailed(r))
    {           AppLog("pCanvas->Show() failed.\n");
        delete pCanvas;
        return;
    }

    delete pCanvas;

}

void
HelloWorld::OnBackground(void)
{
}

void
HelloWorld::OnLowMemory(void)
{
    // TODO:
    // Deallocate as many resources as possible.
}

void
HelloWorld::OnBatteryLevelChanged(BatteryLevel batteryLevel)
{
    // TODO:
    // It is recommended that the application save its data,
    // and terminate itself if the application consumes much battery
}

Code for Helloworldentry.cpp

/**
* OSP Application entry point(OspMain) introduced.
*/
#include <fapp.h>
#include "HelloWorld.h"

using namespace Osp::Base::Collection;

extern "C"
{
    __declspec(dllexport) void OspMain(int hInstance, int argc, char *argv[]);
}

/**
* Entry function of OSP Application which is called by the operating system.
*/
extern "C" {
void OspMain(int hInstance, int argc, char *argv[])
{
    AppLog("OspMain() Started. \n");

    result r = E_SUCCESS;

    ArrayList* pArgs = new ArrayList();
    pArgs->Construct();
    for (int i = 0; i < argc; i++)
    {
        String* pEachArg = new String(argv[i]);
        pArgs->Add(*pEachArg);
    }

    r = Osp::App::Application::Execute(HelloWorld::CreateInstance, pArgs);
    if (IsFailed(r))
    {
        AppLog("Application execution has failed.\n");
    }

    if (pArgs)
    {
        pArgs->RemoveAll(true);
        delete pArgs;
    }

    AppLog("OspMain() Ended. \n");
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-09-23 05:32:49

编译器抱怨您定义了具有此签名的方法:

Osp::App::Application HelloWorld::CreateInstance()

HelloWorld 类声明其 CreateInstance 方法具有此签名:

Osp::App::Application* HelloWorld::CreateInstance()

请注意返回类型的差异。类定义表示具有此名称的方法返回一个 Application 指针,但您已经实现了一个返回 Application 对象< /em>。

将来,请发布代码以及编译器错误。脱离产生这些错误的代码,很难充分解释编译器错误。例如,在这种情况下,我无法告诉您哪种返回类型是正确的;我只能告诉你返回类型不匹配(这正是编译器已经说过的)。

The compiler is complaining that you have defined a method with this signature:

Osp::App::Application HelloWorld::CreateInstance()

whereas the HelloWorld class declares that its CreateInstance method has this signature:

Osp::App::Application* HelloWorld::CreateInstance()

Note the difference in the return type. The class definition says that the method with this name returns an Application pointer but you have implemented a method that returns an Application object.

In the future, please post code along with compiler errors. It's rarely possible to adequately explain compiler errors in isolation from the code that produced them. For example, I can't tell you which return type is correct in this case; I can only tell you that the return types don't match (which is exactly what the compiler already said).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文