1

重複の可能性:
Visual Studio 2008 Express で最小限の SDL プログラムをコンパイルしてリンクするにはどうすればよいですか?

だから私はC ++が初めてで、クラスを作成する必要があります。これは、Sprite.cpp のメソッドの実装と関係があると思います。

プロパティとメソッドを持つ単純なクラスの例を教えてください。または、少なくとも私が間違っていることを教えてください。

エラー #1

Error   12  error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: void __thiscall std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >::_Compat(class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?_Compat@?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEXABV12@@Z)   D:\GSE\Game with Jon Bye\game\game\main.obj

エラー #2

Error   13  error LNK1120: 1 unresolved externals   D:\GSE\Game with Jon Bye\game\Debug\game.exe    1

Sprite.h

#include <string>
#include <SDL.h>
#include "Functions.h"

using namespace std;

class Sprite
{
private:
    int PosX;
    int PosY;
    int xDist;
    int yDist;
    string ImagePath;
    SDL_Surface Screen;
    SDL_Surface *temp, *sprite, *screen;

public:
    Sprite(int PosX, int PosY, string ImagePath, SDL_Surface Screen );
    void Sprite::DrawSprite( int x, int y, SDL_Surface *sprite, SDL_Surface *screen )
    {
        //Make a temporary rectangle to hold the offsets
        SDL_Rect offset;

        //Give the offsets to the rectangle
        offset.x = x;
        offset.y = y;

        //Blit the surface
        SDL_BlitSurface( sprite, NULL, screen, &offset );

        SDL_UpdateRect(screen, 0, 0, 0, 0);
    }

    void Sprite::Draw()
    {
        #pragma region Char to String Conversion

        string ImagePath;
        char * writable = new char[ImagePath.size() + 1];
        copy(ImagePath.begin(), ImagePath.end(), writable);
        writable[ImagePath.size()] = '\0';

        #pragma endregion
        temp = SDL_LoadBMP(writable);
        sprite = SDL_DisplayFormat(temp);
        SDL_FreeSurface(temp);

        // free the string after using it
        delete[] writable;

        DrawSprite(PosX, PosY, sprite, screen);
    }

    void Sprite::Move(int xDist, int yDist)
    {
        PosX += xDist;
        PosY += yDist;
        Draw();
    };
};

スプライト.cpp

#include "Sprite.h"

Sprite::Sprite(int posX, int posY, std::string imagePath, SDL_Surface screen) :        PosX(posX), PosY(posY), ImagePath(imagePath), Screen(screen)
{
    void DrawSprite( int x, int y, SDL_Surface *sprite, SDL_Surface *screen );
    void Draw();
    void Move(int xDist, int yDist);
}
4

2 に答える 2

0

ベクトルを使用して検索する場合のC++の未解決の外観

リリースモードではなく、デバッグモードでした。

選択した新しいリリースモードでリンカー設定などを設定し、リリースプロジェクトをビルドしていることを確認してください。

于 2012-12-16T13:11:59.550 に答える
0

ああ、相棒のジョナサン・オー!結局、SDLを使用するようにという私のアドバイスを受け入れたようです...

エラーの意味はわかりませんが、SDL では次のようにする必要があることはわかっています。

#undef main

あなたの後:

#include <SDL.h> 

そうしないと機能しません。なんで?何らかの理由で、SDL は「main」をどこかに定義しているため、「SDL.h」をインクルードするとリンカが異常終了し、すべてが混乱します (main はエントリ関数であるため)。

おそらくこれがエラーの原因ですが、私はそれを疑っていますが、エラーメッセージは文字列と関係があるようです...

また、Sprite.CPP ファイルで何が起こっているのかよくわかりません。まだ C++ に不慣れで、C++ でクラスを作成する方法を検討している場合は、ここにいくつかの C++ チュートリアルがあります。私が C++ を学び始めた方法です: http://thenewboston.org/list.php?cat=16

于 2012-12-16T01:47:36.777 に答える