What's wrong with this C++ code?

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
// items.cpp
// inventory structure using inheritance
#include <iostream.h>

const int LEN = 80; // maximum length of item names

class item // item class
{
private:
char name[LEN]; // item name
char look[LEN]; // long item description
unsigned int number; // item type (1-9)
unsigned long value; // item value (0+)
double weight; // item weight (>0)
public:
void getData()
{
cout << &quot;Enter item name: &quot;;
cin >> name;

cout << &quot;Enter long item description: &quot;;
cin.getline(look, LEN, '\n');

cout << endl << &quot;Enter item type (1-9): &quot;;
cin >> number;

cout << endl << &quot;Enter item value (0+): &quot;;
cin >> value;

cout << endl << &quot;Enter item weight (>0): &quot;;
cin >> weight;
}
};

class weapon : public item // weapon class
{
private:
int minDamage; // minimum hit damage
int maxDamage; // maximum hit damage
public:
void getData()
{
weapon::getData();
cout << &quot;Enter minimum damage: &quot;;
cin >> minDamage;
cout << &quot; Enter maximum damage: &quot;;
cin >> maxDamage;
}
};

When I compile, I just get an illegal operation error and poof it goes.
 

BowDown

Banned
Jun 2, 2000
2,197
0
0
I know C, but not C++... Guess I can't help ya there. We use the <stdio.h> mostly and scanf and printf for your cout, cin.


:disgust::frown::confused:
 

BigToque

Lifer
Oct 10, 1999
11,700
0
76
is that all the source?

do you not need a 'main' function?

i have not programmed anything in c++ in a long time, so i've forgotten almost everything i learned in class.
 

mjquilly

Golden Member
Jun 12, 2000
1,692
0
76
Yeah, you will need a main() function if you plan on compiling this. You can't just compile header files.
 

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
I have a main looks like it didn't get pasted. I did find the problem and fix it. Now onto problem #2, the getline.