Char String Won't Recognize

Im trying to make a 'make your own bug' program sort to speak, and One of my members in the class Bug is called bugName where I am trying to let the user create a name for the bug.

Here is my code for the program and im getting this error when I am trying pass the bugName to the printTraits() function.
1>Bug Class.obj : error LNK2019: unresolved external symbol "public: void __thiscall Bug::printTraits(char * const,int,int,char)" (?printTraits@Bug@@QAEXQADHHD@Z) referenced in function "public: void __thiscall Bug::getTraits(void)" (?getTraits@Bug@@QAEXXZ)
1>C:\Users\Christopher\Documents\Visual Studio 2010\Projects\CIS 247 Week 3 Lab\Debug\CIS 247 Week 3 Lab.exe : fatal error LNK1120: 1 unresolved externals
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
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>;
#include <cstring>;
using namespace std;

class Bug
{
private:
	char bugName[30];
	int numEyes;
	int numLegs;
	char color;
public:
	void getTraits();
	void printTraits(char[30], int, int, char);

	Bug();
	Bug(char[30], int, int, char);
};

int main ()
{
	Bug myBug;
	
	cout << "Welcome To 'Creat Your Own Bug" << endl;
	cout << "You will be selecting different traits throughout the program to create a custom bug of your choice" << endl;
	cout << "-------------------------------" << endl << endl;
	myBug.getTraits();

	return 0;
}

Bug::Bug()
{
	bugName;
	numEyes = 0;
	numLegs = 0;
	color = '*';
}

Bug::Bug( char[30], int nE, int nL, char col)
{
	bugName;
	numEyes = nE;
	numLegs = nL;
	color = col;
}

void Bug::getTraits()
{
	cout << "To begin, lets give you bug a name: ";
	cin >> bugName;
	cout << endl << "Now, your bug gets a choice of a number of Eyes, Legs, and A color of your choice\n";
	cout << "How many Eyes would you like your Bug to have(at Least 2)? ";
	cin >> numEyes;
	if (numEyes < 2)
	{
		numEyes = 2;
	}
	else {
		numEyes = numEyes;
	}
	cout << endl << "How many legs would you like you bug to have(at Least 2)?" ;
	cin >> numLegs;
	if (numLegs < 2)
	{
		numLegs = 2;
	}
	else {
		numLegs = numLegs;
	}
	cout << endl << "Lastly, what color would you like your bug to be: " << endl;
	cout << "w : White\nb : Blue\n g : Green\ny : Yellow\n";
	cin >> color;
	cout << endl << endl;
	cout << "-------------------------------" << endl;
	printTraits(bugName, numEyes, numLegs, color);
}


I will greatly appreciate any advice any of you can give me =)
You're misunderstanding char arrays. I'd recommend against using them.

Use std::string instead:

1
2
3
4
5
6
7
8
9
10
11
#include <string>

//...

class Bug
{
private:
//  char bugName[30];   // <-  boo
    string bugName;  // <- yay

// etc 

I like the way you illustrated that lol.
That takes care of that problem but now I'm getting the issue of Line 51 (in the code I posted above.
1>c:\users\christopher\documents\visual studio 2010\projects\cis 247 week 3 lab\cis 247 week 3 lab\bug class.cpp(51): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
I'm not so sure of on how to fix this either
Topic archived. No new replies allowed.