#include "stdafx.h" //includes all my headers
usingnamespace std;
class Player_Setup{
private:
char pname[15]; //this is the char array
int crossheir_min;
int crossheir_max;
int crossheirs_type;
int x, y, z;
float xzdeg;
float ydeg;
public:
Player_Setup()
{pname = "no name\0";} // '\0' isn't working
Player_Setup(char name[15])
{pname = name;}
char[15] Player_Name() // i don't know how to return an array
{return pname;}
int Crossheir_Size(bool type)
{if (type == 0) return crossheir_min;
elsereturn crossheir_max;}
void Change_Crossheir_Type(int type)
{crossheirs_type = type;}
int Crossheir_Type(){return crossheirs_type;}
void Change_Name(char name[15]) //this wont work
{pname = name;}
void Display_Name()
{cout << pname;} //this is all that works
};
the problems are that the functions wont work. can any one help?
I got 3 errors. 1st was: "error C2440: '=' : cannot convert from 'const char [15]' to 'char [15]'" how do i fix that? the other two were both "error C2440: '=' : cannot convert from 'char []' to 'char [15]'"
Since you are using a C++ class, why not just use std::string?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <string>
usingnamespace std;
class Player_Setup{
private:
string pname;
int crossheir_min;
etc
public:
Player_Setup():
pname( "no name" )
{ }
etc
};
Also, using the #include <stdafx.h> is a kludgy Microsoft thing. You should not rely on it. You are better off just listing the exact headers you need. That way you won't be surprised or annoyed later on when you make changes to any part of your program or compile environment.