Overloading Contructors

I'm creating Bio's for a couple of characters in a game of mine, I'm just starting out learning classes from a course I'm on...

I'm getting an error message see declaration of Character_Bio::Character_Bio
can someone explain where I'm going wrong?

(It works without the second constructor..)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>


//creates a new class called Character_Bio
class Character_Bio
{
public:
	std::string strName;
	int nAge;
	int nWeight;
	std::string strFrom;
	std::string strStyle;

//constructor of class
	Character_Bio(std::string x, int age, int weight, std::string from, std::string style)
	{
		strName = x;
		nAge = age;
		nWeight = weight;
		strFrom = from;
		strStyle = style;
	}

//Overloading a constructor
Character_Bio(std::string x2, int age2, int weight2, std::string from2, std::string style2)
{

		strName = x2;
		nAge = age2;
		nWeight = weight2;
		strFrom = from2;
		strStyle = style2;

}

};




int main()
{

//object of class Character_Bio (name,age,weight,from,style,story)
Character_Bio c1("Gozo",17,180,"The Kingdom of Ereos","Freestyle");
//object of class Character_Bio (name,age,weight,from,style,story)
Character_Bio c2("King Rhizord",175,480,"The Kingdom of Zordane","No Style");



std::cout << "Characters name:  "<< c1.strName << std::endl;
std::cout << "Age:  "	 << c1.nAge << " years old " << std::endl;
std::cout << "Weight:  " << c1.nWeight << " lbs" << std::endl;
std::cout << "From:  "   << c1.strFrom  << std::endl;
std::cout << "Style:  "  << c1.strStyle << std::endl;
//
std::cout << "Characters name:  "<< c2.strName << std::endl;
std::cout << "Age:  "	 << c2.nAge << " years old " << std::endl;
std::cout << "Weight:  " << c2.nWeight << " lbs" << std::endl;
std::cout << "From:  "   << c2.strFrom  << std::endl;
std::cout << "Style:  "  << c2.strStyle << std::endl;


	return 0;
}
When overloading functions and constructors the parameters need to differ in some way. It could be in the number of parameters and/or the types of the parameters. In your code you have declared both constructors to have equal number of parameters all of the same type.
I see..

Thank you!

I got it working now, I just swapped a couple of the parameters around so that it isn't identical and it compiles.
Topic archived. No new replies allowed.