Hey all, I am trying to figure this class thing out and still cannot get it right. I keep on getting these errors which make no sense to me at all and even worse I am using a template right out of the book. here is the code: Code: #include <iostream.h> #include <string> class dog { private: public: void bark(void); void chasecar(void); void beg(void); dog(); }; //Constructor dog::dog() { } void dog::bark(void) { int x; for(x= 0; x < 5; x++) { cout <<"Bark" << endl; } cout << "The squirrl ran away" <<endl; } void dog::chasecar(void) { int y; for(y = 0; y < 5; y++) { cout << "Vroom!" << endl; } cout << "The dog must have got tired" << endl; } void dog::beg(void) { cout <<"Look at those eyes" << endl; } int main() { dog harry(); harry.bark(void); harry.beg(void); harry.chasecar(void); cin.ignore(256, '\n'); cout << "Press ENTER to continue..." << endl; cin.get(); return 0; } I am going to try inserting a string to name the damn dog but that wasn't working at all because the compiler refused to recognize 'string' anywhere. I deleted it for now but still keep getting these errors I cannot fix. 55 C:\Documents and Settings\Bill\My Documents\class dog.cpp request for member `bark' in `harry', which is of non-class type `dog ()()' 55 C:\Documents and Settings\Bill\My Documents\class dog.cpp expected primary-expression before "void" 56 C:\Documents and Settings\Bill\My Documents\class dog.cpp request for member `beg' in `harry', which is of non-class type `dog ()()' 56 C:\Documents and Settings\Bill\My Documents\class dog.cpp expected primary-expression before "void" every single function I use I get this error and I have no idea what's causing it Thanks Bill
I am using g++ in Fedora 4 linux. First of all, with this: Code: #include <iostream.h> #include <string> I got this: Code: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. I have been learning to use this: Code: #include <iostream> #include <string> using namespace std; Which took care of that. Then I got it to compile with the following changes: Code: int main() { dog harry; // dog harry(); It seemed to me that here you // should be declaring a class, not calling function harry.bark(); // harry.bark(void); harry.beg(); // harry.beg(void); harry.chasecar(); // harry.chasecar(void); . . . . . ...and a run gave me this: Code: $ ./psppb1 Bark Bark Bark Bark Bark The squirrl ran away Look at those eyes Vroom! Vroom! Vroom! Vroom! Vroom! The dog must have got tired Press ENTER to continue... If that came directly from the book, it wasn't edited very well was it... or is it old
Hey thanks for the reply! I got it to work using Code: int main() { dog harry; harry.bark(); harry.beg(); harry.chasecar(); cin.ignore(256, '\n'); cout << "Press ENTER to continue..." << endl; cin.get(); return 0; } it wasn't from the book I was playing around with the book format. I am just trying to figure the concept of class out. I am using Dev C++ for windows but I do run debian linux on this machine as well. Thanks again! Bill