Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-12-2005, 06:50 PM   #1
Member (9 bit)
 
Join Date: Jun 2003
Posts: 290
problem with using classes.

alright. i keep getting this message:
library.h: In member function `void Book::AddBook()':
library.h:36: error: no match for 'operator>>' in 'std::cin >>
temp->Book::bookID'

here is my library.h

Code:
#include 
using std::cout;
using std::cin;
using std::endl;
class Book
{
public:
char bookName[40];
int bookID[10];
int numCopies;
Book *next;
Book(int=0);
void AddBook();
};
Book *current;
Book *start_ptr = NULL;
Book::Book(int copies) : numCopies(copies){}
void Book::AddBook() //add book to end of list
{
Book *temp, *temp2;
temp = new Book;
cout << "\nEnter title of book: ";
cin >> temp->bookName;
cout << "\nEnter ID: ";
cin >> temp->bookID;
cout << "\nEnter number of copies: ";
cin >> temp->numCopies;
temp->next = NULL;
if(start_ptr == NULL) //if list is empty
{
start_ptr = temp;
current = start_ptr;
}
else
{
temp2 = start_ptr;
while(temp2->next != NULL)
temp2 = temp2->next;
temp2->next = temp;
}
}
it is supposed to add a Book to the end of the link list.
ACLerok is offline   Reply With Quote
Old 04-13-2005, 06:09 PM   #2
Member (9 bit)
 
Join Date: Jun 2003
Posts: 290
Quote:
Originally Posted by ACLerok
alright. i keep getting this message:
library.h: In member function `void Book::AddBook()':
library.h:36: error: no match for 'operator>>' in 'std::cin >>
temp->Book::bookID'

here is my library.h

Code:
#include 
using std::cout;
using std::cin;
using std::endl;
class Book
{
public:
char bookName[40];
int bookID[10];
int numCopies;
Book *next;
Book(int=0);
void AddBook();
};
Book *current;
Book *start_ptr = NULL;
Book::Book(int copies) : numCopies(copies){}
void Book::AddBook() //add book to end of list
{
Book *temp, *temp2;
temp = new Book;
cout << "\nEnter title of book: ";
cin >> temp->bookName;
cout << "\nEnter ID: ";
cin >> temp->bookID;
cout << "\nEnter number of copies: ";
cin >> temp->numCopies;
temp->next = NULL;
if(start_ptr == NULL) //if list is empty
{
start_ptr = temp;
current = start_ptr;
}
else
{
temp2 = start_ptr;
while(temp2->next != NULL)
temp2 = temp2->next;
temp2->next = temp;
}
}
it is supposed to add a Book to the end of the link list.
anyone?
ACLerok is offline   Reply With Quote
Old 04-30-2005, 12:41 PM   #3
Member (9 bit)
 
cuog's Avatar
 
Join Date: Aug 2004
Location: powhatan "the stix" VA
Posts: 511
Send a message via AIM to cuog Send a message via Skype™ to cuog
Cool

What language are u using and could u attatch the files or email them to me at fst79ta@gmail.com and i can try and help you if that is c/c++/c#
__________________
|>Sempron64 3000+ @2450 Mhz and counting||1.5 gb AData V-Series RAM||Biostar TForce6100 skt754 || eVGA 7600GT KO 600 core/803 mem||
|> Dual 1.26 GHz Pentium III || 2GB ECC Registered RAM || 18gb scsi 10 HD||
cuog is offline   Reply With Quote
Old 05-01-2005, 05:37 AM   #4
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
I think it is Java or C++

anyway,

the probelm here is you( ACLerok ) delcared an array of integer in BOOKID:

|||||||||||||||||||||||||||||||||||||||||||
class Book
{
public:
char bookName[40];
int bookID[10];<-----------------This is an array of 10 integers!!!
int numCopies;
Book *next;
Book(int=0);
void AddBook();
};

|||||||||||||||||||||||||||||||||||

If you want integer with 10 digits you should have used

long bookID;

if your BOOKID have characters in it:

char bookID[10];

got it?

Last edited by alfie2; 05-01-2005 at 06:08 AM.
alfie2 is offline   Reply With Quote
Old 05-01-2005, 07:46 PM   #5
Member (9 bit)
 
cuog's Avatar
 
Join Date: Aug 2004
Location: powhatan "the stix" VA
Posts: 511
Send a message via AIM to cuog Send a message via Skype™ to cuog
its C++ and it appears to me that the arrays were declared wrong o ill have to get a look at that, its easy to tell it isnt java because the extension for java are .java/.jar/.class and a few others i think but ill get to playing with the code and trying to solve it as soon as i can
cuog is offline   Reply With Quote
Old 05-02-2005, 06:32 AM   #6
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
=====================
class Book
{
public:
char bookName[40];
int bookID[10];
int numCopies;
Book *next;
Book(int=0);
void AddBook();
};
====================

my point is this:

if one declare:

int bookID[10];

then one can NOT do the following:

cout << "\nEnter ID: ";
cin >> temp->bookID; <-----trying to insert a number into a pointer
is an illegal operation!

The following statements are of correct syntax:

cout << "\nEnter ID: ";
cin >> temp->bookID[0];<---first element in array "bookID"


or
cin >> temp->bookID[1];<---second element in array "bookID"
or
:
:
cin >> temp->bookID[9];<---tenth and last element in array "bookID"

------------
if one try to read a large 10-digit # like 9876543210
then one declares a "LONG" integer or use a "CHAR" array.
since the largest signed 32-bit integer is 2147483647
and unsigned is 4294967295

a LONG integer is infinte( well, whatever the system memory can hold anyway)

////////////////////////////////////
or you can delcare:

char bookID[10];

then the following is totally LEGAL and program compiles/runs fine:

cout << "\nEnter ID: ";
cin >> temp->bookID;
/////////////////////////////////////
alfie2 is offline   Reply With Quote
Old 05-02-2005, 10:26 AM   #7
Member (9 bit)
 
cuog's Avatar
 
Join Date: Aug 2004
Location: powhatan "the stix" VA
Posts: 511
Send a message via AIM to cuog Send a message via Skype™ to cuog
yeah i see it was an indexer mmistake it appears these arrays are a little wierd to me since I just switched over to C languages from java but its prety cool I hope u keep at it and have a lot of fun programming
cuog is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:21 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2