| | |
Error declaring class, pls help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 4
Reputation:
Solved Threads: 0
I have this error but cant seem to see why. This code compiled would give 1 error. Anyone please advise, thanks.
C Syntax (Toggle Plain Text)
#include <string> using namespace std; class Beverage{ protected: Beverage *beverage; string desc; public: friend class Bev_Iterator; Beverage(){ beverage = 0; desc = "unknown beverage"; } virtual string getdesc(){ return desc; } virtual double cost(){ return 0; } Bev_Iterator* Iterator(); }; Bev_Iterator* Beverage::Iterator(){ return new Bev_Iterator((Beverage*) this); //error here }; class Bev_Iterator{ Beverage *bev, *next; public: Bev_Iterator(Beverage *bev){ this->bev=bev; } void moveFirst(){ next=bev; } Beverage *Next(){ Beverage *t=next; next=next->Beverage; return t; } bool hasNext(){ return (next!=0); } };
Finally got it to compile by removing the code you have after the class declarations and reformatting to make it easier to read. Don't be afraid of using spaces in your program -- crunching everything up like you have it makes debugging difficult if not sometimes impossible.
c Syntax (Toggle Plain Text)
#include <string> using namespace std; class Beverage; class Bev_Iterator { protected: const Beverage *bev; const Beverage *next; public: Bev_Iterator(const Beverage *bev) { this->bev=bev; this->next = 0; } }; class Beverage { protected: Beverage *beverage; string desc; public: friend class Bev_Iterator; Beverage() { beverage = 0; desc = "unknown beverage"; } virtual string getdesc() { return desc; } virtual double cost() { return 0; } Bev_Iterator* Iterator() { return new Bev_Iterator(this); //error here } };
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
When you get an error with your code, please post that next time. Anyways, the error I got was that on line 19 you declare a Bev_Iterator* without having declared the class first. Put this line before the definition of the Beverage class:
There maybe be other errors, I didn't check thoroughly.
[edit:] look like Ancient Dragon put a li'l more time into it
C Syntax (Toggle Plain Text)
class Bev_Iterator;
[edit:] look like Ancient Dragon put a li'l more time into it
Last edited by Infarction; Apr 3rd, 2007 at 9:58 pm.
![]() |
Similar Threads
- tictactoe help..i dunno wats wrong...i need some1 to correct it...it has some error. (C#)
- Cannot Find Server or DNS Error - Secure Sites Pls Review HiJacks Log (Viruses, Spyware and other Nasties)
- Linker Error in derived class initialization (C++)
- Error while declaring Crystal Report Object (ASP.NET)
- Error While Declaring Crytal Report Object (VB.NET)
Other Threads in the C Forum
- Previous Thread: airline reservation
- Next Thread: How to pass dynamic arrays?
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush fgets file fork forloop framework frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o incrementoperators kernel kilometer km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue multi mysql number odf open opensource openwebfoundation owf pattern pdf performance pointer pointers posix probleminc process program programming pyramidusingturboccodes read recursion recv repetition research scanf scheduling scripting segmentationfault send shape socket socketprograming stack standard string strings systemcall testautomation unix user voidmain() wab win32api windows.h






