Ejemplo n.º 1
0
int main() {

    Dog dog;
    dog.speak();

    return 0;
}
Ejemplo n.º 2
0
int main()
{
  Dog fido; // create a dog
  fido.speak();
  fido.wagTail();
  std::cout << "Fido is " << fido.getAge() << " years old\n";
  return 0;
}
Ejemplo n.º 3
0
int main()
{
  Dog fido;
  Dog rover(5);
  Dog buster(6, 8);
  Dog yorkie(3, YORKIE);
  Dog dobbie(4, 20, DOBERMAN);
  fido.speak();
  rover.wagTail();
  std::cout << "Yorkie is "
      << yorkie.getAge() << " years old\n";
  std::cout << "Dobbie weighs "
      << dobbie.getWeight() << " pounds\n";
  return 0;
}
Ejemplo n.º 4
0
int main()
{
    cout << "Creating dog." << endl;
    Dog dog;
    dog.speak();
    cout << "Creating cat." << endl;
    Cat cat;
    cat.speak();
    cout << "Creating bird." << endl;
    Bird bird;
    bird.speak();
    cout << "All animals created." << endl << endl;

    cout << "Creating pet pointer array." << endl;
    cout << "Adding created pets to array." << endl;
    Pet* petPtr[3] = {&dog, &cat, &bird};
    cout << "Iterating over array." << endl;
    for(int i = 0; i < (int) (sizeof(petPtr) / sizeof(*petPtr)); i++) {
        petPtr[i]->speak();
    }

    cout << endl << "Creating array of dynamically allocated animals." << endl;
    Pet* dynAllocPets[3] = {new Dog, new Cat, new Bird};
    cout << "Iterating over array." << endl;
    for(int i = 0; i < (int) (sizeof(dynAllocPets) / sizeof(*dynAllocPets)); i++) {
        dynAllocPets[i]->speak();
    }
    cout << "Calling destructors." << endl;
    for(int i = 0; i < (int) (sizeof(dynAllocPets) / sizeof(*dynAllocPets)); i++) {
        dynAllocPets[i]->~Pet();
    }

    /*
    cout << endl << "Trying to declare oject of type Pet (will not compile)." << endl;
    Pet pet;*/
    return 0;
}
Ejemplo n.º 5
0
int main() {
  Dog simba;  // Richard's dog
  simba.speak();
  simba.eat();
} ///:~
int main() {
  Dog simba;  // Pies Richarda
  simba.speak();
  simba.eat();
} ///:~