Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ArcticTiger

C++ Error Message that makes no sense

This topic is 5454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently trying to write an application that will set up a database for Game Players to register with, to start off I have tried to set up a Class to take the player details and return them when requested. The only problem is I get a load of error messages that make no sense to me. Here is the code Player.h
#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
#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;
}
Errors
e:\Visual Studio Projects\FileIOTest\Player.cpp(25): error C2371: ''Player::getfirstname'' : redefinition; different basic types
e:\Visual Studio Projects\FileIOTest\Player.cpp(35): error C2371: ''Player::getemail'' : redefinition; different basic types
e:\Visual Studio Projects\FileIOTest\Player.cpp(20): error C2371: ''Player::getnick'' : redefinition; different basic types
e:\Visual Studio Projects\FileIOTest\Player.cpp(40): error C2371: ''Player::getpassword'' : redefinition; different basic types
e:\Visual Studio Projects\FileIOTest\Player.cpp(55): error C2371: ''Player::getratio'' : redefinition; different basic types
e:\Visual Studio Projects\FileIOTest\Player.cpp(30): error C2371: ''Player::getsurname'' : redefinition; different basic types
e:\Visual Studio Projects\FileIOTest\Player.cpp(35): error C2556: ''int Player::getemail(void)'' : overloaded function differs only by return type from ''std::string Player::getemail(void)''
e:\Visual Studio Projects\FileIOTest\Player.cpp(25): error C2556: ''int Player::getfirstname(void)'' : overloaded function differs only by return type from ''std::string Player::getfirstname(void)''
e:\Visual Studio Projects\FileIOTest\Player.cpp(20): error C2556: ''int Player::getnick(void)'' : overloaded function differs only by return type from ''std::string Player::getnick(void)''
e:\Visual Studio Projects\FileIOTest\Player.cpp(40): error C2556: ''int Player::getpassword(void)'' : overloaded function differs only by return type from ''std::string Player::getpassword(void)''
e:\Visual Studio Projects\FileIOTest\Player.cpp(55): error C2556: ''int Player::getratio(void)'' : overloaded function differs only by return type from ''float Player::getratio(void)''
e:\Visual Studio Projects\FileIOTest\Player.cpp(30): error C2556: ''int Player::getsurname(void)'' : overloaded function differs only by return type from ''std::string Player::getsurname(void)''
e:\Visual Studio Projects\FileIOTest\Player.cpp(61): warning C4244: ''='' : conversion from ''int'' to ''float'', possible loss of data
 
Please help!

Share this post


Link to post
Share on other sites
Advertisement
You forgot to specify the return types of functions in your source file.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You must suply the return type both in the declaration and in the definition of a function;

Player::getfirstname()

When you leave it out, the compiler think´s that the function will return an int.

Do

string Player::getfirstname()

and that goes for the rest of your function that returns a string





Share this post


Link to post
Share on other sites
You''ll want to put code guards up in your head file too.

eg.

#ifndef _PLAYER_H
#define _PLAYER_H
class Player
{
...
}
#endif






--{You fight like a dairy farmer!}

Share this post


Link to post
Share on other sites
except that:

#pragma once is not standard C++ code ... so why would you use it (most people I know always start from a basic template file anyway, and the guards are in there)

Share this post


Link to post
Share on other sites
I am using Visual Studio .NET and it set up the class like that. As long as it runs I aren''t too bothered as this for a University project. If it runs, it passes!

Thanks for the advice guys!

Share this post


Link to post
Share on other sites
Always beware when visualstudio does something like that, it may work in your compiler, but when you go and try to compil it on someone elses system, it may blow up

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!