Sign in to follow this  

Basic C++ Class Problem

This topic is 3667 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

Hello, Ive been learning C#, but i decided to make something in C++ and I'm having a small problem. Im making a class called "Player" and I'm declaring a constructor and when i create the definition for it, it says it cannot have a return type, but I didnt give it one:
1>c:\documents and settings\brandon\my documents\visual studio 2008\projects\the pen\the pen\player.cpp(16) : error C2533: 'Player::{ctor}' : constructors not allowed a return type
My Code:
Player::Player(std::string & Name)
{
	m_Health = 100;
	m_Level = 1;
	m_Name = Name;
}
Thanx for any help.

Share this post


Link to post
Share on other sites
Library.h
//////////////////////////////////////////////////////////////
//
// Library.h
// Desc: Contains all the header files needed
//
//////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>


Player.h
//////////////////////////////////////////////////////////////
//
// Player Class
//
//////////////////////////////////////////////////////////////

#include "Library.h"

class Player
{
int m_Health;
int m_Level;
std::string m_Name;
public:
Player(std::string & Name);
int GetHealth();
int GetLevel();
std::string GetName();
}


Player.cpp
//////////////////////////////////////////////////////////////
//
// Player.cpp
// Desc: Contains all the function definitions
//
//////////////////////////////////////////////////////////////

#include "Player.h"

////////////////////////////////////
// Name: Player
// Desc: Constructor
////////////////////////////////////

Player::Player(std::string & Name)
{
m_Health = 100;
m_Level = 1;
m_Name = Name;
}

////////////////////////////////////
// Name: GetHealth
// Desc: Returns the players health
////////////////////////////////////

int Player::GetHealth()
{
return m_Health;
}

////////////////////////////////////
// Name: GetLevel
// Desc: Returns the players level
////////////////////////////////////

int Player::GetLevel()
{
return m_Level;
}

////////////////////////////////////
// Name: GetName
// Desc: Returns the players name
////////////////////////////////////

std::string Player::GetName()
{
return m_Name;
}

Share this post


Link to post
Share on other sites

This topic is 3667 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this