我大約花了兩週時間學習C++,並決定開始一個足球模擬遊戲。我創建了一個名爲player的類,從那以後,我一直在收到一個編譯錯誤。然而,即使我評論出課程,我仍然得到錯誤:無法解析的外部符號
1> football1.obj:error LNK2019:無法解析的外部符號「public:__thiscall player :: player(void)」(?? 0player @@ QAE @XZ)函數引用_wmain
下面是代碼:
// football.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <Wincon.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
class player{
private:
static const int quarterbackspeed=10;
public:
player();
int ret(){return quarterbackspeed;}
};
int _tmain(int argc, _TCHAR* argv[])
{
//maximize console window
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd,SW_SHOWMAXIMIZED);
//DECLARE FOOTBALL FIELD
char field[27][57];
//declare sidelines x=0,x=51,y=0,y=121
int times=0;
for(int declarex=0;times<2;declarex=26){
for(int declarey=0;declarey<57;declarey++){
field[declarex][declarey]='x';}times++;}
times=0;
for(int declarey=0;times<2;declarey=56){
for(int declarex=1;declarex<26;declarex++){
field[declarex][declarey]='x';}times++;}
//declare north endzone
for(int declarey=1;declarey<3;declarey++){
for(int declarex=1;declarex<26;declarex++){
field[declarex][declarey]='*';}}
//declare south endzone
for(int declarey=54;declarey<56;declarey++){
for(int declarex=1;declarex<26;declarex++){
field[declarex][declarey]='*';}}
//declare playing field
for(int declarex=1;declarex<26;declarex++){
for(int declarey=3;declarey<54;declarey++){
field[declarex][declarey]=' ';}}
//DECLARE PLAYERS
player manning;
cout<<manning.ret();
//display field
for (int declarey=0;declarey<57;declarey++){
cout<<endl;
for (int declarex=0;declarex<27;declarex++){
cout<<field[declarex][declarey];}}
system("PAUSE");
return 0;
}