Jump to content
  • Advertisement
Sign in to follow this  
NUCLEAR RABBIT

Basic C++ Class Problem

This topic is 3977 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
Advertisement
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
Sign in to follow this  

  • 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!