need helpw/a error message

This is a discussion on need helpw/a error message within the C++ Programming forums, part of the General Programming Boards category; I don't understand why i keep getting this error message, hich is at the bottom of the page. Script started ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    need helpw/a error message

    I don't understand why i keep getting this error message, hich is at the bottom of the page.

    Script started on Thu Nov 29 21:35:58 2001
    strauss.udel.edu% cat card.h

    // header file for card class



    #ifndef CARD_H

    #define CARD_H





    #include <iostream>

    using std :: istream;



    class Card {

    friend istream &operator>>(istream &, Card &);

    private:

    char *name;

    int size3;

    int *phone;

    int CardID;

    int BookID;

    public:

    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>



    Card :: Card (char *n, int *p, int c, int b)

    {

    strcpy(n, name);

    phone = p;

    CardID = c;

    BookID = b;

    }

    istream &operator>>(istream &input, Card &c) {



    input >> c.name >> c.phone >> c.CardID

    >> c.BookID;
    return input;

    }

    void Card :: print() {



    cout << name << endl;

    cout << phone << endl;

    cout << CardID << endl;

    cout << BookID << endl;

    }

    Card :: ~Card() {



    delete [] name;

    delete [] phone;

    }

    Card :: Card(const Card &c) {



    name = new char[strlen(c.name) + 1];

    assert(name != 0);

    size3 = (strlen(name) + 1);



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

    name[i] = c.name[i];



    phone = new int[13];

    assert(phone != 0);



    for(int j = 0; j < 13; j++)

    phone[j] = c.phone[j];



    CardID = c.CardID;

    BookID = c.BookID;

    }

    void Card :: setBookID(int b) {



    BookID = (b >= 0) ? b : 0;



    }

    //Card &Card :: operator=(const Card &c) {

    //}











    strauss.udel.edu% make

    CC -c card.cc

    "card.cc", line 18: Error: The operation "std::basic_istream<char, std::char_traits<char>> >> int*" is illegal.

    1 Error detected.

    *** Error code 2

    make: Fatal error: Command failed for target `card.o'

    strauss.udel.edu% exit

    strauss.udel.edu%
    script done on Thu Nov 29 21:36:18 2001

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    43

    Smile

    im not sure if this is causing the error, but who knows, its always the stupid stuff
    im pretty sure the istream overload should be in the public section of your class...anything is worth a shot

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    ah ha! i think i see the problem, is your implementation prepared for you to use the input thing more than once?
    i know on a project i had a problem with that using the cout operator, unless you return a pointer, or something you cant do something like cin << blah << blah blah << etc...

    i can dig up the syntax for the return if you need it

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    upon second glance i see you do have the return, blah...guess im no help, sorry

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    this pointer

    What you might be thinking of is the this pointer, which you return in overloaded << or >> operator functions to allow cascaded returns, like input << x << y << z; etc.
    the return is:
    return this;
    I don't know if that's the problem, but may be what DarkDays means.

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    yes! thats what i was trying to say
    once finals come around me forget english =)

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21