Player.h構造函數的參數
#ifndef HEADER_GUARD_PLAYER
#define HEADER_GUARD_PLAYER
#include <string>
using std::string;
//Parent player class
class Player
{
private:
protected:
string playerName;
int chipCount;
public:
//Constructor
Player();
Player(string name);
};
//Custom Players
class PlayerSteven: public Player
{
};
class PlayerBlake: public Player
{
};
class PlayerTucker: public Player
{
};
#endif
Player.cpp
#include "Player.h"
#define STARTCHIPS 1500
Player::Player()
{
chipCount = STARTCHIPS;
playerName = "Default";
};
Player::Player(string name)
{
playerName = name;
};
Main.cpp的
#include <iostream>
#include "Deck.h"
#include "Player.h"
#include <string>
using namespace std;
int main()
{
Deck deck;
PlayerSteven steven = new PlayerSteven("Steven");
PlayerBlake blake = new PlayerBlake("Blake");
PlayerTucker tucker = new PlayerTucker("Tucker");
deck.shuffle();
int x = 0;
int y = 0;
for (int i = 0; i < 52; i++)
{
deck.nextCard(x,y);
cout << x << "," << y << endl;
}
system("PAUSE");
return 0;
}
錯誤:
11 C:\用戶\文檔\ temp中\ p_comp.cpp沒有用於調用PlayerSteven :: Play的匹配函數erSteven(爲const char [7]) '
11 C:\用戶\文檔\ TEMP \ p_comp.cpp沒有匹配函數調用`PlayerSteven :: PlayerSteven(爲const char [7])'
音符C:\ Dev-Cpp \ PROJECTS \ Player.h:26 PlayerSteven :: PlayerSteven(const PlayerSteven &)
任何人都知道我可以得到這個編譯?
謝謝。
你試過了什麼? – djechlin 2013-04-30 14:43:28
爲什麼你讓你的「自定義球員」強壯的類型?它們與基礎'Player'類沒有什麼不同,並且你沒有做任何與需要的類型相關的特定任何東西。例如,正確的方法是實例化實際類型,即Player Steven(「Steven」)。 – Chad 2013-04-30 14:46:09
@djechlin:你什麼意思?他試圖編譯這個問題中的代碼。 – 2013-04-30 14:47:01