Jump to content

  • Log In with Google      Sign In   
  • Create Account


Having a problem with virtual methods


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Jeff D   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 October 2001 - 05:15 AM

I got this code here that is giving me an unexpected end of file found error I cant seem to find a reason why. I am gonna use the source tags for the first time so I hope it works:
  

#include <iostream.h>
#include <stdlib.h>

class mammal
{

   public:
      mammal() { cout << "Mammal constructor \n";
                 setage(); };
      mammal(int age) { cout << "Mammal constructor \n";
                    setage(age); }; 
      virtual ~mammal() { cout << "Mammal destructor \n"; };
      virtual void speak() const { cout << "Mammal speak! \n"; };
      void move() { cout << "Mammal Moves! \n"; };
      void setage() { itsage = 1; };
      void setage(int age) {itsage = age; };
      void getage() { cout << itsage << endl; };
   
   protected:
      int itsage;

};

class dog : public mammal
{

   public:
      dog() { cout << "Dog constructor \n"; }; 
      virtual ~dog() { cout << "Dog destructor \n"; ); 
      void speak() { cout << "Woof! \n"; };
      void move() { cout << "dog moves! \n"; };

};

int main()
{
   mammal* fido = new dog;
   fido -> getage();
   fido -> speak();
   fido -> move();
   system("PAUSE");
   return 0;

}

  
I hope that works. I know that the program is quite juvenile but Im trying my hardest to create a progrm in a book without looking at it to seem if I actually can get the syntax right. But the book looks like this to and I still get this error. Thx, Jeff Desrosiers

Sponsor:

#2 Jeff D   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 October 2001 - 05:18 AM

the 2 includes are actually on different lines not sure why that happened.


Thx,

Jeff Desrosiers

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 October 2001 - 05:47 AM

Check out this line:

virtual ~dog() { cout << "Dog destructor \n"; );

See anything wrong with it?

--Jeff



#4 Jeff D   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 October 2001 - 05:49 AM

LOL thx a lot man.



#5 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 12 October 2001 - 07:38 PM

I might add that you have a bunch of redundant statement terminators (normal people call them "semicolons" ). When you do:
int setage() {itsage = 1;}; 

the last semicolon is unnecessary. (Just information.)

#6 Jeff D   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 October 2001 - 07:51 PM

Ah I see I tried this and it still worked thx a lot.



Thx,

Jeff Desrosiers




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS