リンカ ツール エラー LNK2019とグローバル変数について。

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
XKXY

リンカ ツール エラー LNK2019とグローバル変数について。

#1

投稿記事 by XKXY » 15年前

今度はリンカ ツール エラー LNK2019とグローバル変数に悩まされています。
どうすればよろしいのでしょうか?

以下問題のソースコードとエラーメッセージ

bitmap.hの中身。

#ifndef BITMAP_GAME
#define BITMAP_GAME

template <class type>
class Graphics
{
public:;
void screen_up();
void mario();
};
class Bitmap
{
protected:
int z;
public:
int get_z();
void change_z(const int& set_z);
};
static Graphics<Bitmap> graphics;
#endif

bitmap.cppの中身
#include "bitmap.h"

template <class type>
void Graphics<type>::screen_up()
{
};
template <class type>
void Graphics<type>::mario()
{
};
int Bitmap::get_z()
{
return z;
};
void Bitmap::change_z(const int& set_z)
{
z=set_z;
};



scene.hの中身
#ifndef SCENE_GAME
#define SCENE_GAME

#include "bitmap.h"
class Scene_Base
{
public:
virtual void main();
};

#endif

scene.cppの中身

#include "scene.h"

void Scene_Base::main()
{
graphics.screen_up();
graphics.mario();
};

KKXY

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#2

投稿記事 by KKXY » 15年前

エラーメッセージを忘れていました。

コンパイルしています...
bitmap.cpp
main.cpp
scene.cpp
コードを生成中...
マニフェストをリソースにコンパイルしています...
Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
Copyright (C) Microsoft Corporation. All rights reserved.
リンクしています...
scene.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Graphics::mario(void)" (?mario@?$Graphics@VBitmap@@@@QAEXXZ) が関数 "public: virtual void __thiscall Scene_Base::main(void)" (?main@Scene_Base@@UAEXXZ) で参照されました。
scene.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Graphics::screen_up(void)" (?screen_up@?$Graphics@VBitmap@@@@QAEXXZ) が関数 "public: virtual void __thiscall Scene_Base::main(void)" (?main@Scene_Base@@UAEXXZ) で参照されました。
C:\Users\kimura keigo\Documents\Visual Studio 2008\Projects\実験_2\Debug\実験_2.exe : fatal error LNK1120: 外部参照 2 が未解決です。

MNS

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#3

投稿記事 by MNS » 15年前

class Graphics
{
public:;
    ↑このセミコロンが問題では?

KKXY

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#4

投稿記事 by KKXY » 15年前

はずしてみましたが問題解決にはなりませんでした。

MNS

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#5

投稿記事 by MNS » 15年前

確かに、文法上は間違いではなかったですね(そうなのか?)

コードを全て開示していただかないと、これ以上私はわかりませんね。
(グローバル変数に悩まされているということですが、そのグローバル変数も見当たりませんし。)

KKXY

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#6

投稿記事 by KKXY » 15年前

一番上の文章の27行目あたりに
static Graphics<Bitmap> graphics;
と書いてあるはずなんですが・・・。
これがグローバル変数のはずなんですけど・・・。

hoge

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#7

投稿記事 by hoge » 15年前

template はヘッダファイルに移動。


あと、
static Graphics<Bitmap> graphics;
これは、本当にヘッダファイルに書く必要あるの?

KKXY

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#8

投稿記事 by KKXY » 15年前

hogeさんがいったようにやってみたら解決しました。
どうもありがとうございました。

MNS

Re:リンカ ツール エラー LNK2019とグローバル変数について。

#9

投稿記事 by MNS » 15年前

本当ですね。すいません、見逃していました。

閉鎖

“C言語何でも質問掲示板” へ戻る