GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Nov-2003, 17:39
ArcticTiger ArcticTiger is offline
New Member
 
Join Date: Nov 2003
Posts: 1
ArcticTiger is an unknown quantity at this point

C++ Error that makes no sense!


Please someone help, I am trying to code a c++ game player database but when i compile the class Player i get this error with all of the functions that are returning strings.

error C2371: 'Player::getemail' : redefinition; different basic types

this is the code

Player.h

CPP / C++ / C Code:
#pragma once
#include <STRING>
using namespace std;


class Player
{
private:
	int score;
	string nickname, firstname, surname, email, password;
	int played;
	float ratio;
public:
	Player(string nick, string fname, string sname, string mail, string pass);
	~Player(void);
	int addscore(int x);
	int getscore();
	int addplayed(int y);
	int getplayed();
	int clacratio();
	float getratio();
	string getnick();
	string getfirstname();
	string getsurname();
	string getemail();
	string getpassword();
};

Player.cpp

CPP / C++ / C Code:
#include "player.h"

Player::Player(string nick, string fname, string sname, string mail, string pass)
{
	nickname = nick;
	firstname = fname;
	surname = sname;
	email = mail;
	password = pass;
	score = 0;
	played = 0;
	ratio = 0;
}

Player::~Player(void)
{
}

Player::getnick()
{
	return nickname;
}

Player::getfirstname()
{
	return firstname;
}

Player::getsurname()
{
	return surname;
}

Player::getemail()
{
	return email;
}

Player::getpassword()
{
	return password;
}

Player::getplayed()
{
	return played;
}

Player::addplayed(int y)
{
	played+=y;
}

Player::getratio()
{
	return ratio;
}

Player::clacratio()
{
	ratio = (score/played);
	return 0;
}

Player::addscore(int x)
{
	score+=x;
	return 0;
}

Player::getscore()
{
	return score;
}
  #2  
Old 10-Nov-2003, 08:14
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
When you define your functions, you should also say what each define. When you don't, C++ assumes you're returning a int.

So amend each function like so:
CPP / C++ / C Code:
string Player::getnick()
{
  return nickname;
}

GF
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:37.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.