Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Forked from joshthecoder/cast.ooc
Created January 27, 2010 12:51
Show Gist options
  • Save nddrylliog/287811 to your computer and use it in GitHub Desktop.
Save nddrylliog/287811 to your computer and use it in GitHub Desktop.
The bird is eating worms
The animal is eating stuff
The bird is eating worms
The animal is eating worms
Animal: class {
eat: final func -> String { return "eating stuff" }
}
Bird: class extends Animal {
eat: final func -> String { return "eating worms" }
}
main: func () {
bird := Bird new()
animal := bird as Animal
"The bird is %s" format(bird eat()) println()
"The animal is %s" format(animal eat()) println()
}
Animal: class {
eat: func -> String { return "eating stuff" }
}
Bird: class extends Animal {
eat: func -> String { return "eating worms" }
}
main: func () {
bird := Bird new()
animal := bird as Animal
"The bird is %s" format(bird eat()) println()
"The animal is %s" format(animal eat()) println()
}
#include <iostream>
using namespace std;
class Animal
{
public:
void Eat()
{
cout << "eating stuff" << endl;
}
};
class Bird : public Animal
{
public:
void Eat()
{
cout << "eating worms" << endl;
}
};
int main()
{
Bird* b = new Bird;
Animal* a = (Animal*)b;
cout << "The bird is ";
b->Eat();
cout << "The animal is ";
a->Eat();
return 0;
}
The bird is eating worms
The animal is eating stuff
The bird is eating worms
The animal is eating worms
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void Eat()
{
cout << "eating stuff" << endl;
}
};
class Bird : public Animal
{
public:
virtual void Eat()
{
cout << "eating worms" << endl;
}
};
int main()
{
Bird* b = new Bird;
Animal* a = (Animal*)b;
cout << "The bird is ";
b->Eat();
cout << "The animal is ";
a->Eat();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment