C++でクラスをヘッダファイルに
Posted: 2012年11月08日(木) 20:20
はじめまして
早速なんですがC++をしていてクラスをうまくヘッダファイルに分けられません
**************Main.cpp********************
#include "DxLib.h"
#include "Start.h"
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
S.point();
S.point2();
S.point3();
}
**************Start.h***********************
class Start{
public:
void point();
void point2();
void point3();
} S;
*************point.cpp********************
#include "Start.h"
void Start::point() { };
*************point2.cpp*******************
#include "Start.h"
void Start::point2(){ };
**********************************************
こんな感じで一個ずつ分けたいんですがたぶんMain,point,poin2で "Start.h"を重複インクルード?してるからなのか
動きません エラーは
1>point.obj : error LNK2005: "class Start S" (?S@@3VStart@@A) は既に Main.obj で定義されています。
1>point2.obj : error LNK2005: "class Start S" (?S@@3VStart@@A) は既に Main.obj で定義されています。
1>point2.obj : error LNK2005: "public: void __thiscall Start::point(void)" (?point@Start@@QAEXXZ) は既に point.obj で定義されています。
1>point3.obj : error LNK2005: "class Start S" (?S@@3VStart@@A) は既に Main.obj で定義されています。
1>point3.obj : error LNK2005: "public: void __thiscall Start::point(void)" (?point@Start@@QAEXXZ) は既に point.obj で定義されています。
1>Main.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Start::point3(void)" (?point3@Start@@QAEXXZ) が関数 _WinMain@16 で参照されました。
1>Main.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Start::point2(void)" (?point2@Start@@QAEXXZ) が関数 _WinMain@16 で参照されました。
1>E:\120927\han\Game project\MusicProject\Debug\GameProg.exe : fatal error LNK1120: 外部参照 2 が未解決です。
だれか解決策かもっとわかりやすく典型的なクラスの分け方ありませんか?
早速なんですがC++をしていてクラスをうまくヘッダファイルに分けられません
**************Main.cpp********************
#include "DxLib.h"
#include "Start.h"
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
S.point();
S.point2();
S.point3();
}
**************Start.h***********************
class Start{
public:
void point();
void point2();
void point3();
} S;
*************point.cpp********************
#include "Start.h"
void Start::point() { };
*************point2.cpp*******************
#include "Start.h"
void Start::point2(){ };
**********************************************
こんな感じで一個ずつ分けたいんですがたぶんMain,point,poin2で "Start.h"を重複インクルード?してるからなのか
動きません エラーは
1>point.obj : error LNK2005: "class Start S" (?S@@3VStart@@A) は既に Main.obj で定義されています。
1>point2.obj : error LNK2005: "class Start S" (?S@@3VStart@@A) は既に Main.obj で定義されています。
1>point2.obj : error LNK2005: "public: void __thiscall Start::point(void)" (?point@Start@@QAEXXZ) は既に point.obj で定義されています。
1>point3.obj : error LNK2005: "class Start S" (?S@@3VStart@@A) は既に Main.obj で定義されています。
1>point3.obj : error LNK2005: "public: void __thiscall Start::point(void)" (?point@Start@@QAEXXZ) は既に point.obj で定義されています。
1>Main.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Start::point3(void)" (?point3@Start@@QAEXXZ) が関数 _WinMain@16 で参照されました。
1>Main.obj : error LNK2019: 未解決の外部シンボル "public: void __thiscall Start::point2(void)" (?point2@Start@@QAEXXZ) が関数 _WinMain@16 で参照されました。
1>E:\120927\han\Game project\MusicProject\Debug\GameProg.exe : fatal error LNK1120: 外部参照 2 が未解決です。
だれか解決策かもっとわかりやすく典型的なクラスの分け方ありませんか?