1

BADA 用の単純な 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");
}
}
4

1 に答える 1

0

コンパイラは、この署名でメソッドを定義したと不平を言っています:

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

一方、HelloWorldクラスは、そのCreateInstanceメソッドに次の署名があることを宣言します。

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

戻り値の型の違いに注意してください。クラス定義では、この名前のメソッドはApplication ポインタを返しますが、Application オブジェクトを返すメソッドを実装しています。

今後は、コンパイル エラーとともにコードを投稿してください。コンパイラ エラーを、それを生成したコードから分離して適切に説明することはほとんど不可能です。たとえば、この場合、どの戻り値の型が正しいかはわかりません。戻り値の型が一致しないことしかわかりません (これは、コンパイラが既に言ったこととまったく同じです)。

于 2010-08-30T11:10:05.897 に答える