class???

Please, would you help me? I don`t know why this program doesn`t run.
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
#include <iostream>
#include <string>;
using namespace std;

class Item 
{
public:
	Item ()
	int getPower() const;
	int getWeight() const;
	int getName() const;

	void setPower();
	void setWeight();
	void setName();

	void read();
	void print() const;
		
private:
	int power;
	int weight;
	char name[256];
};

void Item::read()
{
	cout << "Power: ";
	cin >> power;
	cout << "Weight: ";
	cin >> weight;
	cout << "Name: ";

		for (int i=0; i < 256; i++)

	cin >> name[i];
}

void Item::print()
{
	cout << "Power: " << power << endl;
	cout << "Weight: " << weight << endl;
	cout << "Name: " << name << endl;



void main ()
{

	Item Item1;

	Item1.setPower(63);
	Item1.setWeight(86);
	Item1.setName(23);

	cout << Item1.getPower() << endl;
	cout << Item1.getWeight() << endl;
	cout << Item1.getName() << endl;

	system("PAUSE");
} 
Is this all of your program? You are calling setPower, setWeight, and setName member functions for Item1... but I don't seem their implementation and the prototypes don't even accept parameters? Also, you are missing a closing brace on your print() function. Next time post the error messages you are getting. Where are your accessor method implementations?
Last edited on
Errors are:
error C2144: syntax error : 'int' should be preceded by ';' c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 8

error C2511: 'void Item::print(void)' : overloaded member function not found in 'Item' c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 40

fatal error C1004: unexpected end-of-file found c:\documents and settings\доби\my documents\visual studio 2008\projects\prak1\prak1\prak1.cpp 62


Last edited on
Topic archived. No new replies allowed.