本文整理汇总了C++中Dog::speak方法的典型用法代码示例。如果您正苦于以下问题:C++ Dog::speak方法的具体用法?C++ Dog::speak怎么用?C++ Dog::speak使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dog
的用法示例。
在下文中一共展示了Dog::speak方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Dog dog;
dog.speak();
return 0;
}
示例2: main
int main()
{
Dog fido; // create a dog
fido.speak();
fido.wagTail();
std::cout << "Fido is " << fido.getAge() << " years old\n";
return 0;
}
示例3: main
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;
}
示例4: main
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;
}
示例5: main
int main() {
Dog simba; // Richard's dog
simba.speak();
simba.eat();
} ///:~
示例6: main
int main() {
Dog simba; // Pies Richarda
simba.speak();
simba.eat();
} ///:~