-
need help with error messages
I don't understand why I keep getting these error messages.
Script started on Sat Dec 01 15:26:18 2001
strauss.udel.edu% cat card.h
// header file for card class
#ifndef CARD_H
#define CARD_H
#include <iostream>
class Card {
friend istream &operator>>(istream&, Card&);
private:
char *name;
int size3;
int size4;
char *phone;
int CardID;
int BookID;
public:
Card();
Card(char *, int *, int, int);
void print();
~Card();
Card(const Card&);
Card& operator=(const Card&);
int getCardID() {return CardID;}
int getBookID() {return BookID;}
void setBookID(int);
};
#endif
strauss.udel.edu% cat card.cc
//member definitions for card class
#include "card.h"
#include <iostream>
using std :: cout;
using std :: endl;
#include <cassert>
#include <string>
Card :: Card()
{
name = NULL;
phone = NULL;
CardID = 0;
BookID = 0;
}
Card :: Card (char *n, int *p, int c, int b)
{
size3 = strlen(n) + 1;
name = new char[size3];
strcpy(name, n);
size4 = strlen(p) + 1;
phone = new char[size4];
strcpy(phone, p);
CardID = c;
BookID = b;
}
istream &operator>>(istream &input, Card &c)
{
char x[100];
char ch = input.get();
input.getline(x, 100);
c.name = new char[strlen(x) + 1];
strcpy(c.name, x);
input.getline(x, 100);
c.phone = new char[strlen(x) + 1];
strcpy(c.phone, x);
input >> c.CardID >> c.BookID;
return input;
}
void Card :: print() {
cout << name << endl;
cout << phone << endl;
cout << CardID << " " << BookID << endl;
}
Card :: ~Card() {
delete name;
delete phone;
}
Card :: Card(const Card &c) {
if(c.name) {
name = new char[strlen(c.name) + 1];
assert(name != 0);
size3 = (strlen(c.name) + 1);
for(int i = 0; i < size3; i++)
name[i] = c.name[i];
}else
name = NULL;
if(c.phone) {
phone = new char[strlen(c.phone) + 1];;
assert(phone != 0);
size4 = (strlen(c.phone) + 1);
for(int j = 0; j < size4; j++)
phone[j] = c.phone[j];
}else
phone = NULL;
CardID = c.CardID;
BookID = c.BookID;
}
void Card :: setBookID(int b) {
BookID = b;
}
Card &Card :: operator=(const Card &c) {
if(this != c) {
delete name;
name = new char[strlen(c.name) + 1];
strcpy(name, c.name);
phone = new char[strlen(c.phone) + 1];
strcpy(phone, c.phone);
CardID = c.CardID;
BookID = c.BookID;
return *this;
}
}
strauss.udel.edu% make
CC -c card.cc
"card.h", line 9: Warning (Anachronism): Class friends require an explicit "class".
"card.h", line 9: Error: "," expected instead of "&".
"card.h", line 10: Error: Use ";" to terminate declarations.
"card.cc", line 23: Error: Formal argument 1 of type const char* in call to std::strlen(const char*) is being passed int*.
"card.cc", line 25: Error: Formal argument 2 of type const char* in call to std::strcpy(char*, const char*) is being passed int*.
"card.cc", line 33: Error: The type "istream" is incomplete.
"card.cc", line 35: Error: The type "istream" is incomplete.
"card.cc", line 36: Error: name is not accessible from operator>>(istream&, Card&).
"card.cc", line 37: Error: name is not accessible from operator>>(istream&, Card&).
"card.cc", line 39: Error: The type "istream" is incomplete.
"card.cc", line 40: Error: phone is not accessible from operator>>(istream&, Card&).
"card.cc", line 41: Error: phone is not accessible from operator>>(istream&, Card&).
"card.cc", line 43: Error: CardID is not accessible from operator>>(istream&, Card&).
"card.cc", line 43: Error: The type "istream" is incomplete.
"card.cc", line 43: Error: BookID is not accessible from operator>>(istream&, Card&).
"card.cc", line 89: Error: The operation "Card* != const Card" is illegal.
15 Error(s) and 1 Warning(s) detected.
*** Error code 15
make: Fatal error: Command failed for target `card.o'
strauss.udel.edu% exit
strauss.udel.edu%
script done on Sat Dec 01 15:26:39 2001
Popular pages
Recent additions