![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
Hi All,
Finishing up a project, and am encountering a bunch of errors. They all seem to be the same type of error, which is the following (using MS VS.NET 2003): d:\My Documents\Visual Studio Projects\SMRTdb\MovieList.h(161) : error C2664: 'MovieNode::MovieNode(const MovieNode &)' : cannot convert parameter 1 from 'MovieNode *' to 'const MovieNode &' Reason: cannot convert from 'MovieNode *' to 'const MovieNode' No constructor could take the source type, or constructor overload resolution was ambiguous this is repeated in a bunch of functions. Here is my functions header file that is calling trying to reference the list //Global Functions
void EndProg(CustList *, MovieList *);
void RtnMov(CustList *, MovieList *);
void Pay(CustList *);
void HldMov(CustList *, MovieList *);
void RentMov(CustList *, MovieList *);
void DispMov(MovieList *);
void DispCust(CustList *);
void NewCust(CustList *);
void NewMov(MovieList *);
void MainMenu(CustList *cdb, MovieList *mdb)
{
while(1)
{
system("CLS");
cout << "\nMAIN MENU" << endl;
cout << "=========" << endl << endl;
cout << "1. Create new customer" << endl;
cout << "2. Create new movie" << endl;
cout << "3. View/update customer info" << endl;
cout << "4. View/update movie info" << endl;
cout << "5. Rent a movie" << endl;
cout << "6. Place a movie on hold" << endl;
cout << "7. Return a movie" << endl;
cout << "8. Pay Customer Balance" << endl;
cout << "0. Quit" << endl << endl;
cout << "Enter an option: ";
int opt;
cin >> opt;
switch(opt)
{
case 1:
NewCust(cdb);
break;
case 2:
NewMov(mdb);
break;
case 3:
DispCust(cdb);
break;
case 4:
DispMov(mdb);
break;
case 5:
RentMov(cdb, mdb);
break;
case 6:
HldMov(cdb, mdb);
break;
case 7:
RtnMov(cdb, mdb);
break;
case 8:
Pay(cdb);
break;
case 0:
EndProg(cdb, mdb);
return;
break;
default:
cout << "That was not a valid option, please try again!" << endl;
break;
}
}
cout << "\n Press a key";
cin >> NULL;
return;
}
void EndProg(CustList *cdb, MovieList *mdb)
{
cout << "Writing changes to customer database..." << endl;
Sleep(4000);
cdb->SavCustList();
delete cdb;
cout << "Writing changes to movie database..." << endl;
Sleep(4000);
mdb->SavMovList();
delete mdb;
cout << "Done updating databases." << endl << endl;
cout << "Thank you for using SMRTdb." << endl;
cout << "Bye bye now." << endl;
return;
}
void RtnMov(CustList *cdb, MovieList *mdb)
{
int acctnum, movid;
cout << "\nCustomer account number: ";
cin >> acctnum;
CustNode *cust = cdb->SearchCust(acctnum);
if (cust->next != NULL)
{
//remove rental status from customer account
movid = cust->RMovieID;
cust->isRenting = 0;
cust->dueDate = 0;
cust->RMovieID = 0;
cout << "Customer account updated." << endl;
//remove rental status from movie database
MovieNode *mov = mdb->SearchMov(movid);
if (mov->next !=NULL)
{
mov->DueDate = 0;
mov->isRent = 0;
mov->RentCustNum = 0;
cout << "Movie record updated." << endl;
}
}
return;
}
void Pay(CustList *cdb)
{
int acctnum;
cout << "\nCustomer account number: ";
cin >> acctnum;
double cred;
cout << "Amount credited: ";
cin >> cred;
CustNode *cust = cdb->SearchCust(acctnum);
if (cust->head != NULL)
{
cust->balance -= cred;
cout << "New balance is: " << cust->balance << endl;
}
return;
}
void HldMov(CustList *cdb, MovieList *mdb)
{
int acctnum, movid;
cout << "\nCustomer account number: ";
cin >> acctnum;
CustNode *cust = cdb->SearchCust(acctnum);
if (cust->next != NULL)
{
//check to see if already holding or locked
if (cust->isHolding || cust->isLocked)
{
if (cust->isHolding)
cout << "This customer is already holding a movie." << endl;
else if (cust->isLocked)
cout << "This customer's account has been locked." << endl;
}
else
{
cout << "Movid ID: ";
cin >> movid;
//check if movie is already on hold
MovieNode *mov = mdb->SearchMov(movid);
if (mov->next !=NULL)
{
if (mov->isHeld)
cout << "Movie is already on hold by customer " << mov->HoldCustNum << endl;
else
{
mov->isHeld = 1;
mov->HoldCustNum = acctnum;
cout << "Movie is now on hold." << endl;
}
}
}
return;
}
void RentMov(CustList *cdb, MovieList *mdb)
{
int acctnum, movid;
cout << "\nCustomer account number: ";
cin >> acctnum;
CustNode *cust = cdb->SearchCust(acctnum);
if (cust->next != NULL)
{
//check to see if already renting or locked
if (cust->isRenting || cust->isLocked)
{
if (cust->isRenting)
cout << "This customer is already renting a movie." << endl;
else if (cust->isLocked)
cout << "This customer's account has been locked." << endl;
}
else
{
cout << "Movid ID: ";
cin >> movid;
//check if movie is already rented
MovieNode *mov = mdb->SearchMov(movid);
if (mov->next !=NULL)
{
if (mov->isRent)
cout << "Movie is already rented by customer " << mov->RentCustNum << endl;
cout << "Try placing a hold." << endl;
else if (cust->HMovieID == movid)
{
mov->isRent = 1;
mov->RentCustNum = acctnum;
mov->isHeld = 0;
mov->HoldCustNum = 0;
cust->HMovieID = 0;
cust->isHolding = 0;
cust->isRenting = 1;
cust->RMovieID = movid;
cust->dueDate = 2005;
mov->isRent = 1;
mov->RentCustNum = acctnum;
mov->DueDate = 2005;
mov->timesRented++;
cout << "Movie is now rented." << endl;
}
else
{
cust->isRenting = 1;
cust->RMovieID = movid;
cust->dueDate = 2005;
mov->isRent = 1;
mov->RentCustNum = acctnum;
mov->DueDate = 2005;
mov->timesRented++;
cust->balance += 3.99;
cout << "Movie is now rented." << endl;
}
}
}
}
return;
}
void DispMov(MovieList * mdb);
{
int movid;
cout << "Enter the movie ID: ";
cin >> movid;
MovieNode * mov = mdb->SearchMov;
if (mov->next != NULL)
{
cout << "\n\nMOVIE DETAILS" << endl;
cout << "=============" << endl;
cout << "Movie ID: " << mov->MovieID << "\tMovie Title: " << mov->Title << "\tReleased: " << mov->ReleaseYear << endl;
cout << "Director: " << mov->Director << "\tLead Actor: " << mov->Star << endl;
cout << "Genre: " << mov->Genre << "\tRent Code: " << mov->RentCode << endl;
cout << "Movie Status" << endl;
cout << "============" << endl;
cout << boolalpha << "Rented? " << mov->isRent;
if (mov->isRent)
cout << "\tCustomer Account: " << mov->RentCustNum << "\tDue: " << mov->DueDate << endl;
cout << boolalpha << "\tOn Hold? " << mov->isHeld;
if (mov->isHeld)
cout << "\tCustomer Account: " << mov->HoldCustNum << endl;
cout << "\nUPDATING" << endl;
cout << "========" << endl;
cout << "If no change desired, enter 0." << endl;
char newcode;
cout << "\nNew rent code: ";
cin >> newcode;
if (newcode != '0')
mov->RentCode = newcode;
char rmHold;
cout << "Remove a hold? (y/n): ";
cin rmHold;
if (rmHold == 'y')
{
mov->isHeld = 0;
mov->HoldCustNum = 0;
}
}
return;
}
void DispCust(CustList * cdb)
{
int acctnum;
cout << "\nCustomer account number: ";
cin >> acctnum;
CustNode *cust = cdb->SearchCust(acctnum);
if (cust->next != NULL)
{
cout << "\n\nCUSTOMER INFORMATION" << endl;
cout << "====================" << endl;
cout << "Account #: " << cust->acctnum << "\tName: " << cust->custname << endl;
cout << "Address: " << cust->custaddr << "\tPhone #: " << cust->custphone << endl;
cout << boolalpha << "Account Balance: $" << cust->balance << "\tLock on Account: " << cust->isLocked << endl;
cout << "\nRENT AND HOLDING STATUS" << endl;
cout << "=======================" << endl;
cout << boolalpha << "Currently Renting? " << cust->isRenting;
if (cust->isRenting)
cout << "\tMovie ID: " << cust->RMovieID << "Due: " << cust->dueDate << endl;
cout << boolalpha << "\tCurrently Holding? " << cust->isHolding;
if (cust->isHolding)
cout << "\tMovie ID: " << cust->HMovieID << endl;
cout << "\nUPDATE INFO" << endl;
cout << "===========" << endl;
cout << "If you do not wish to update an option, enter 0. Please do not use spaces in answers." << endl;
string addr;
cout << "New address: ";
cin >> addr;
if (addr != "0")
cust->custaddr = addr;
string tel;
cout << "New phone number: ";
cin >> tel;
if (tel != "0")
cust->custphone = tel;
char hold;
cout << "Remove Hold? (y/n): ";
if (hold == 'y')
{
cust->isHolding = 0;
cust->HMovieID = 0;
}
char lock;
cout << "Remove Lock? (y/n): ";
if (lock == 'y')
cust->isLocked = 0;
}
return;
}
void NewCust(CustList * cdb)
{
int acctnum;
string custname;
string custaddr;
string custphone;
cout << "Please enter the following information. Do not use any spaces." << endl;
cout << "Account Number: ";
cin >> acctnum;
cout << "Customer Full Name: ";
cin >> custname;
cout << "Street Address, City, Prov, Postal Code: ";
cin >> custaddr;
cout << "Phone number: ";
cin >> custphone;
cdb->appendtoCust(acctnum, custname, custaddr, custphone, 0, 0, 0, 0, 0, 0, 0);
cout << "\n\nCustomer has been added to the system" << endl;
return;
}
void NewMov(MovieList * mdb)
{
int MovieID;
string Title;
string Director;
string Star;
char Genre;
int ReleaseYear;
char RentCode;
cout << "Please enter the following information. Do not use any spaces." << endl;
cout << "Movie ID #: ";
cin >> MovieID;
cout << "Title: ";
cin >> Title;
cout << "Year Released: ";
cin >> ReleaseYear;
cout << "Director: ";
cin >> Director;
cout << "Lead Actor: ";
cin >> Star;
cout << "Genre Code: ";
cin >> Genre;
cout << "Rental Code: ";
cin >> RentCode;
mdb->append(MovieID, Title, Director, Star, Genre, ReleaseYear, RentCode, 0, 0, 0, 0, 0, 0);
cout << "Movie has been added to the database.";
return;
}And here is one of the two class headers containing the list (both list classes operate similarly) class CustList
{
private:
CustNode *head;
public:
CustList()
{
head = NULL;
}
void appendtoCust (int acctnum, string custname, string custaddr, string custphone, double balance, bool IisRenting, int dueDate, int RMovieID, bool isHolding,int HMovieID, int isLocked)
{
CustNode *b;
CustNode *q;
b=new CustNode( acctnum, custname, custaddr, custphone, balance, IisRenting, dueDate, RMovieID, isHolding,HMovieID, isLocked);
b->next = NULL;
if(head == NULL)
{
//first element
//set node to point to the list
b->next = head;
head=b;
}
else
{
//lets get to the right spot
q = head;
while(q->next != NULL)
{
q = q->next;
}
b->next = q->next;
q->next = b;
}
}
int GetCustHeight(char * filename)
{
int height = 0;
char buffer[300];
ifstream in;
in.open(filename);
if(in.fail())
{
cout << "Failure in function GetHeight" << endl;
return -1;
}
while(!in.eof()) // while we're not at the end of the file..
{
in.getline(buffer, 300); // get a line from the file
height++; // increment height by 1
}
in.close(); // close the file (its no longer needed)
return height; // height will have a count of the number of rows in the file
}
void FillCust (char * Filename)
{
int acctnum; //customer's account number
string custname; //customer's full name
string custaddr; //customer's address
string custphone; //customer's phone number
double balance; //account balance
bool isRenting; //true if customer is currently renting a movie
int dueDate; //date movie is due
int RMovieID; //id number of rented movie
bool isHolding; //true if customer has a movie on hold
int HMovieID; //id number of held movie
int isLocked;
ifstream Cust;
Cust.open(Filename);
if (Cust.fail())
{
cout<<"FAILED"<<endl;
}
int height = GetCustHeight(Filename);
for (int i=1;i<=height;i++)
{
Cust>>acctnum>>custname>>custaddr>>custphone>>balance>>isRenting>>dueDate>>RMovieID>>isHolding>>HMovieID>>isLocked;
appendtoCust(acctnum,custname,custaddr,custphone,balance,isRenting,dueDate,RMovieID,isHolding,HMovieID,isLocked);
}
}
void DeleteCustItem(int ActNum)
{
// search through the list for item and if found
// delete it
if(head == NULL)
{
cout << "Cannot delete from empty list" << endl;
return;
}
// one item list
if(head->next == NULL)
{
if(head->acctnum == ActNum)
{
delete head;
head = NULL;
return;
}
}
// 2 or more items in list
CustNode * current = head;
CustNode * prev;
while(current->next != NULL)
{
prev = current;
current = current->next;
if(current->acctnum == ActNum)
{
prev->next = current->next;
delete current;
return;
}
}
}
void PrintCustList()
{
CustNode *p = head;
while(p != NULL)
{
cout<<(p->acctnum)<<" "<<(p->custname)<<" "<<(p->custaddr)<<" "<<(p->custphone)<<" "<<(p->balance)<<" "<<(p->isRenting)<<" "<<(p->dueDate)<<" "<<(p->RMovieID)<<" "<<(p->isHolding)<<" "<<(p->HMovieID)<<" "<<(p->isLocked)<<endl;
p=p->next;
}
}
void SavCustList()
{
ofstream out;
out.open("customers.txt");
CustNode *p = head;
while(p != NULL)
{
out<<(p->acctnum)<<" "<<(p->custname)<<" "<<(p->custaddr)<<" "<<(p->custphone)<<" "<<(p->balance)<<" "<<(p->isRenting)<<" "<<(p->dueDate)<<" "<<(p->RMovieID)<<" "<<(p->isHolding)<<" "<<(p->HMovieID)<<" "<<(p->isLocked)<<endl;
p=p->next;
}
out.close();
}
CustNode SearchCust(int ActNum)
{
//create null node to return in error
CustNode * blank = head;
// search through the list for item
if(head == NULL)
{
cout << "We have no customers" << endl;
return blank;
}
// one item list
if(head->next == NULL)
{
if(head->acctnum == ActNum)
return blank;
else
{
cout << "We don't have that customer on file" << endl;
return blank;
}
}
// 2 or more items in list
CustNode * current = head;
CustNode * prev;
while(current->next != NULL)
{
prev = current;
current = current->next;
if(current->acctnum == ActNum)
{
return current;
}
else
{
cout << "We don't have that customer on file" << endl;
;
}
}
return current; //in case of error, this should be NULL
}
}and finally, here is one of the two Node classes (again, both customer and movie nodes are similar) class CustNode
{
friend class CustList;
private:
int acctnum; //customer's account number
string custname; //customer's full name
string custaddr; //customer's address
string custphone; //customer's phone number
double balance; //account balance
bool isRenting; //true if customer is currently renting a movie
int dueDate; //date movie is due
int RMovieID; //id number of rented movie
bool isHolding; //true if customer has a movie on hold
int HMovieID; //id number of held movie
int isLocked; //true if customer account is locked
CustNode * next;
public:
// default constructor
CustNode()
{
acctnum=9999;
custname=" ";
custaddr=" ";
custphone="xxxXXX-XXXX";
balance=0;
isRenting=false;
dueDate=00;
RMovieID=00;
isHolding=false;
HMovieID=00;
isLocked=false;
next=NULL;
}
CustNode ( int IN_acctnum, string IN_custname, string IN_custaddr, string IN_custphone, double IN_balance, bool IN_isRenting, int IN_dueDate, int IN_RMovieID, bool IN_isHolding,int IN_HMovieID, int IN_isLocked)
{
acctnum=IN_acctnum;
custname=IN_custname;
custaddr=IN_custaddr;
custphone=IN_custphone;
balance=IN_balance;
isRenting=IN_isRenting;
dueDate=IN_dueDate;
RMovieID=IN_RMovieID;
isHolding=IN_isHolding;
HMovieID=IN_HMovieID;
isLocked=IN_isLocked;
next=NULL;
}
// destructor
~CustNode()
{
cout << "Destroying " << this->custname << endl;
}
};Can anyone give me a hand as to why I'm getting such errors? Thanks. Cat |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Header files are NOT the files where you implement.
That said, I don't see your MovieList.h either. Can you zip your program, and upload it? If it's too big, try http://www.megaupload.com/
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#3 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
As nnxion said, you haven't provided an example of the code that is causing the problem.
From the error message, and the code you have given, the problem is most likely to be in code that is using your classes, and you are mixing up pointers and references (eg a copy constructor expects to receive a reference, not a pointer). If I had to guess further, you've translated your code from a language like Java or C# (in those languages, everything is a reference whereas in C++ pointers and references are different [although related] things). One other rule of fixing errors in C++ (or C) code is "fix the first error first". When beginners get a lot of errors from a C++ compiler, they often try to fix the error reported at the bottom of the screen (or end of the log file). The error at the bottom is the LAST error the compiler has reported. The problem is, in nontrivial code, that code that triggers the compiler to report the first error can confuse the compiler on later code --- the last error message can simply result from a confused compiler, and the actual cause may be one of the earlier reported errors. The most likely cause of an error message like; Quote:
// some_node is a pointer to MovieNode (i.e. of type MovieNode *)
MovieNode something(some_node); // some_node is a pointer to MovieNode (i.e. of type MovieNode *)
MovieNode something(*some_node);Incidentally, your subject line has no relationship to your problem. The fact you're working with a linked list is irrelevant to the fact you're getting error messages from the compiler that you don't understand. You might try reading the sticky post on "how to post a question" as it gives pointers on how to ask questions in a way that increases your chances of a useful answer. |
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
I apologize, I was trying to give snippets of my functioning code rather than posting the whole entire project on here.
Thanks for your suggestion nnxion, I have attached my project in zip format in its entirety. Hopefully that will help. Also, that error was at the top of my error list, along with countless others of the same error code. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
As I said, you need to read the sticky post on how to ask a question. It is better to provide a SMALL but COMPLETE example that illustrates your problem, rather than posting your whole project. nnxion gave you a bum steer by suggesting you post your project. The process of finding such an example may help the penny drop for you (i.e. you may find the cause yourself) and, if you fail to find the cause, other people have more chance of being able to help.
In any event, the cause of your error message is this member function of class MovieNode; MovieNode SearchMov(int movid)
{
//create null node to send back in error
MovieNode * blank = head;
// search through the list for item
if(head == NULL)
{
cout << "Error: No Movies In Database!" << endl;
return blank;
}
// more code removed .....
}My guess is that you either need to change the function so it returns a pointer, viz. MovieNode *SearchMove(int movid) // note the asterix return *blank; // note the asterix |
|
|
|
|
|
#6 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|