本文整理汇总了C++中Dog::print方法的典型用法代码示例。如果您正苦于以下问题:C++ Dog::print方法的具体用法?C++ Dog::print怎么用?C++ Dog::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dog
的用法示例。
在下文中一共展示了Dog::print方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
Dog vdog;
Pet vpet;
vdog.name = "Tiny";
vdog.breed = "Great Dane";
vpet = vdog;
//vpet.breed; is illegal since class Pet has no member named breed
Dog *pdog;
pdog = new Dog;
pdog->name = "Tiny";
pdog->breed = "Great Dane";
Pet *ppet;
ppet = pdog;
ppet->print(); // These two print the same output:
pdog->print(); // name: Tiny breed: Great Dane
//The following, which accesses member variables directly
//rather than via virtual functions, would produce an error:
//cout << "name: " << ppet->name << " breed: "
// << ppet->breed << endl;
//generates an error message: 'class Pet' has no member
//named 'breed' .
//See Pitfall section "Not Using Virtual Member Functions"
//for more discussion on this.
return 0;
}
示例2: main
int main() {
std::cout << "DOG:" << std::endl;
Dog myDog;
myDog.setName("Barkley");
myDog.setWeight(10);
myDog.print();
std::cout << "OWNEDDOG:" << std::endl;
OwnedDog ownedDog;
ownedDog.setName("OwnedBarkley");
ownedDog.setOwner("Ale");
ownedDog.setWeight(20);
ownedDog.print();
return 0;
}