views:

1602

answers:

3

I don't even know where to go with this. Google wasn't very helpful. As with my previous question. I'm using TextMate's Command+R to compile the project.

game.h:16:error: declaration of ‘Player* HalfSet::Player() const’

players.h:11:error: changes meaning of ‘Player’ from ‘class Player’

game.h:21:error: ‘Player’ is not a type

player.h file (partial)

#ifndef PLAYERS_H
#define PLAYERS_H
using namespace std;

#include <string>
#include <vector>
#include <istream>
#include <iomanip>
#include "generics.h"

class Player{ //Line 11
public:
 //getters
 long Id() const;
 string FirstName() const;
 string LastName() const;
 string Country() const;
 //setters
 void setId(long id);
 void setFirstName(string s);
 void setLastName(string s);
 void setCountry(string s);
 //serializing functions
 void display(ostream &out);
 void read(istream &in);
 void write(ostream &out);
 //Initalizers
 Player();
 Player(istream &in);
 Player(string firstName, string lastName);
 Player(string firstName, string lastName, string country);
 Player(long id, string firstName, string lastName, string country);
 ~Player();
private:
 long _id;
 string _firstName;
 string _lastName;
 string _country;
};

game.h file (partial)

#ifndef GAME_H
#define GAME_H

#include "generics.h"
#include "players.h"
#include <string>
#include <vector>
#include <istream>
#include <iomanip>

using namespace std;

class HalfSet{
public:
 //getters
 Player* Player() const; //Line 16
 int GamesWon() const;
 int TotalPoints() const;
 int Errors() const;
 //setters
 void setPlayer(Player* p);
 void setGamesWon(int games);
 void setTotalPoints(int points);
 void setErrors(int errors);
 //Serialization
 void display(ostream &out) const;
 void read(istream &in) const;
 void write(ostream &out) const;
 //Initalizers
 HalfSet();
 ~HalfSet();
private:
 Player* _player;
 int _gamesWon;
 int _points;
 int _errors;
};

What is going on here?

A: 

Looks like the compiler doesn't recognize Player, which prevents you from using it as a return type. Could you show us players.h?

Gordon Wilson
I just added it. :)
epochwolf
+4  A: 

In C++ you cannot name a function the same name as a class/struct/typedef. You have a class named "Player" and so the HalfSet class has a function named "Player" ("Player *Player()"). You need to rename one of these (probably changing HalfSet's Player() to getPlayer() or somesuch).

SoapBox
Thank you, my project now compiling completely.
epochwolf
Well - you can, but not a member function.
Richard Corden
+2  A: 

Your problem is that names are looked up in scopes. Within the declaration of HalfSet::setPlayer(Player*), the unqualified name Player needs to be looked up. The first scope tried is class HalfSet. In that scope, the lookup of Player finds function HalfSet::Player, not global class ::Player.

The solution is to use a qualified name, ::Player. This tells the compiler which scope to use for lookup (global) which in turn means HalfSet::Player is not even considered.

MSalters