string overload error?

I am trying to use a string so I can add a persons name but i keep getting an overload error?

1
2
3
4
class Character
{
public:
	Character(string Name);


It works when its an int but not a string , any ideas to why this may be?
Last edited on
Have you #included the proper header file to use the string class? How are you scoping the string class to the std namespace?
I believe so

1
2
3
#include <iostream>
#include <string>
using namespace std;
How are you passing the string to the constructor?
Also what other constructors do you have for your class?

Character::Character(string Name);

Is that how it is passed to the constructor. Only learnt it last week.
What is the full text of the error?
I have these they all work apart from the string and char

1
2
3
4
5
6
7
8
	Character(string Name);
	string GetName();
	Character(int Age);
	int GetAge()const;
	Character(char Sex);
	char GetSex;
	Character(int ExperienceLevel = 0);
	int GetExperienceLevel() const;
Please post a small complete program. It looks like you're confusing constructors with "setter" functions.

This is all I have of the program I am working on.

[code]
#include <iostream>
#include <string>
using namespace std;

class Character
{
public:
Character(string Name);
string GetName();
Character(int Age);
int GetAge()const;
Character(char Sex);
char GetSex;
Character(int ExperienceLevel = 0);
int GetExperienceLevel() const;

Last edited on
You probably don't need or want all of those constructors. As I said you seem to be confusing constructors with functions to set the various variables to a value. You probably don't need any of the constructors if you create setter functions instead.

In any case at present you have two constructors that take the same type of parameter.

1
2
   Character(int Age);
   Character(int ExperienceLevel = 0);


In order to overload any function, including constructors the overloaded functions must have different parameters.

Im going to start over again, see if I can work it out fresh and not have to work through all this mess.

So I cant have two ints?

So I cant have two ints?

Of course you can have a program with two ints. You can even have a class that has two ints. But really what is your real question?

Oh i missread what you wrote, Just noticed you said parameters.
Topic archived. No new replies allowed.