[問題] 應該是linking問題
最近寫程式遇到一個問題
我是用dev c++的compiler
然後用專案來寫
以下是我的程式(應該不是程式問題 可先到最底看錯誤訊息)
game.h:
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
typedef struct data{
int number;
char name[20];
int score;
int level;
time_t date;
data *next;}rank;
void gotoxy0(int x,int y){
static HANDLE hConsole=0;
static int instanceCount=0;
COORD coord;
if(instanceCount==0){
hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
instanceCount=1;
}
coord.X=x-1;
coord.Y=y-1;
SetConsoleCursorPosition(hConsole,coord);
}
int draw();
int load(rank*);
接下來是寫函式的檔案
game.cpp:
#include "game.h"
int draw(){
system("cls");
int y=10;
int oldy=y;
gotoxy0(31,y);
printf("~");
gotoxy0(33,10);
printf("start game");
gotoxy0(33,11);
printf("check score");
gotoxy0(33,12);
printf("exit");
char check;
int judge=1;
while(judge){
if(_kbhit()){
check=_getch();
switch(check){
case 'H':
oldy=y;
if(y>10)y--;
else y=12;
gotoxy0(31,oldy);
printf(" ");
gotoxy0(31,y);
printf("~");
break;
case 'P':
oldy=y;
if(y<12)y++;
else y=10;
gotoxy0(31,oldy);
printf(" ");
gotoxy0(31,y);
printf("~");
break;
case 'M':
if(y==12)exit(0);
if(y==11){
rank *show=NULL;
judge=load(show);
while(show!=NULL){
printf("%d",show->score);}}
if(y==10);
break;
}
}}
return 0;}
然後是main檔案:
gameMain:
#include "game.h"
int main(){
draw();
return 0;}
這三個檔案如果合起來
寫在一起
就不會有問題
也可以正常的使用
但是剛剛分開時
用project方式編譯
就有錯誤訊息
multiple definition of 'gotoxy0(int,int)'
first declared here
ld return 1 exit status
問題是我程式沒有動過
原本可以跑得出來
後來可能改了某幾行(其實只有printf這樣)
就忽然不能了
就算變成原本可以時的程式碼
一樣不能run
請板上強者幫忙
是哪裡問題...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.114.111.236
推
09/09 00:56, , 1F
09/09 00:56, 1F
→
09/09 01:40, , 2F
09/09 01:40, 2F
→
09/09 01:46, , 3F
09/09 01:46, 3F
→
09/09 20:33, , 4F
09/09 20:33, 4F
→
09/09 20:44, , 5F
09/09 20:44, 5F