Player::Player(string _name, Room *starting_room)
{
name = _name;
current_room = starting_room;
}
我有一個錯誤,當我嘗試運行/編譯我「的main.cpp」,我看不出有什麼錯在下面的構造。但我仍然得到這個錯誤:C++預計初步表達錯誤
error: expected primary-expression before '_name'
error: expected primary-expression before '*'
error: cannot call constructor 'Player::Player' directly [-fpermissive]
note: for a function-style cast, remove the redundant '::Player'
error: 'starting_room' was not declared in this scope
編輯1:Player類從代理類
//Player.h
#ifndef PLAYER_H
#define PLAYER_H
#include<string>
#include "Room.h"
#include "Agent.h"
using namespace std;
class Player: public Agent
{
public:
Player();
Player(string _name, Room *starting_room);
virtual bool act(string direction);
};
#endif // PLAYER_H
//"Agent.h"
#ifndef AGENT_H
#define AGENT_H
#include <Room.h>
#include<string>
using namespace std;
class Agent
{
protected:
Room *current_room;
string name;
public:
Agent();
virtual bool act(string) ;
string getName();
string getCurrentRoomName();
string toLower(string temp);
Room* getCurrentRoom();
};
#endif // AGENT_H
你能提供玩家類嗎? –
這可能是因爲缺少包含字符串標題和房間定義 – Raindrop7
'Player'兩次? –