#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
Having a problem with virtual methods
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:
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
the 2 includes are actually on different lines not sure why that happened.
Thx,
Jeff Desrosiers
Thx,
Jeff Desrosiers
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
October 12, 2001 11:47 AM
Check out this line:
virtual ~dog() { cout << "Dog destructor \n"; );
See anything wrong with it?
--Jeff
virtual ~dog() { cout << "Dog destructor \n"; );
See anything wrong with it?
--Jeff
LOL thx a lot man.
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton
I might add that you have a bunch of redundant statement terminators (normal people call them "semicolons" ). When you do:
the last semicolon is unnecessary. (Just information.)
int setage() {itsage = 1;};
the last semicolon is unnecessary. (Just information.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement