当前位置: 首页>>代码示例>>C++>>正文


C++ Cat类代码示例

本文整理汇总了C++中Cat的典型用法代码示例。如果您正苦于以下问题:C++ Cat类的具体用法?C++ Cat怎么用?C++ Cat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){
  Shelter sh;
  Cat c1("Cat1");
  Cat c2("Cat2");
  Cat c3("Cat3");
  Dog d1("Dog1");
  Dog d2("Dog2");
  Dog d3("Dog3");
  
  sh.enqueue(c1);  
  sh.enqueue(d1);
  sh.enqueue(d2);
  sh.enqueue(c2);
  sh.enqueue(c3);
  sh.enqueue(d3);
  
  
  Animal ani = sh.dequeueAny();
  cout << "DeuqeAny: " << ani.getName() << endl;
  Cat cc = sh.dequeueCat();
  cout << "DeuqeCat: " << cc.getName() << endl;
  Dog dd = sh.dequeueDog();
  cout << "DeuqeDog: " << dd.getName() << endl;
  
}
开发者ID:ASHISH0410,项目名称:careerup150,代码行数:25,代码来源:3-7.cpp

示例2: main

 int main()
 {
 Cat * Family[500];
 int i;
 Cat * pCat;
 for (i = 0; i < 500; i++)
 {
 pCat = new Cat;
 pCat->SetAge(2*i +1);
 Family[i] = pCat;
 }
/*
 for (i = 0; i < 500; i++)
 {
 cout << "Cat #" << i+1 << ": ";
 cout << Family[i]->GetAge() << endl;
 } */
 
 cout<<sizeof(Family[0])<<"\t\tbytes"<<endl;
 cout<<sizeof(*Family[0])<<"\t\tbytes"<<endl;
 cout<<sizeof(Family)<<endl;
 cout<<sizeof(*pCat)<<endl;
 cout<<sizeof(pCat)<<endl;
 cout<<sizeof(Cat*)<<endl;
 cout<<sizeof(Cat)<<endl;
 cout<<sizeof(int)<<endl;
 return 0;
 }
开发者ID:aooaboob,项目名称:CPP,代码行数:28,代码来源:eof_pointers_class.cpp

示例3: main

int main(int argc, const char * argv[]) {
    Dog fido;
    Cat kitty;
    fido.talk();
    kitty.talk();
    return 0;
}
开发者ID:DiegoCaridei,项目名称:Exercises-C-,代码行数:7,代码来源:main.cpp

示例4: main

int main(void)
{
	Animal *animal = NULL;
	animal = new Dog;
	animal->cry();
	animal->doWork();
	cout << " -----" << endl;
	Dog * dog = NULL;
	dog = dynamic_cast<Dog*>(animal); //dynamic_cast是将父类指针转换成子类指针
	if (dog != NULL) {
		cout << "转换成功" << endl;
		dog->cry();
		dog->doWork();
	}
	else {
		cout << "转换失败" << endl;
	}
	Cat *cat = NULL;
	//想通过dynamic_cast 将animal转换成一个cat指针
	cat = dynamic_cast<Cat*>(animal); //通过将animal指针转换成Cat指针
	//尝试将一只狗转换成一只猫
	if (cat != NULL) {
		cout << "转换成功" << endl;
		cat->cry();
		cat->doWork();
	}
	else {
		cout << "转换失败" << endl;
	}
	delete animal;
	return 0;
}
开发者ID:shixv,项目名称:test,代码行数:32,代码来源:2dynamic_cast.cpp

示例5: invalid_cast2

// VPTR_NO_NULL-LABEL: define void @_Z13invalid_cast2v
void invalid_cast2() {
  // We've got a pointer to an alloca, so there's no run-time null check needed.
  // VPTR_NO_NULL-NOT: call void @__ubsan_handle_type_mismatch
  // VPTR_NO_NULL: call void @__ubsan_handle_dynamic_type_cache_miss
  Cat cat;
  cat.speak();
}
开发者ID:JaredCJR,项目名称:clang,代码行数:8,代码来源:ubsan-type-checks.cpp

示例6: main

int main(int argc , char* argv[])
{
    if (argc == 1)
    {
        printUsage (&cout , argv [0]);
        return 0;
    }
    Cat MyCat (argc , argv);

    int nPos = isArg (argc , argv);
    ostream* Out = NULL;
    ofstream OutFile;

    if (nPos != -1)
    {
        string Path = getFile (argv [nPos]);
        OutFile.open (Path.c_str () , ios::app);
        Out = &OutFile;
    }
    else
    {
        Out = &cout;
    }
    MyCat.print (Out);
    if (nPos != -1)
    {
        OutFile.close ();
    }
    return 0;
}
开发者ID:TheMassiveChipmunk,项目名称:Simple-C---Project,代码行数:30,代码来源:main.cpp

示例7: mainddddd

int mainddddd (int argc, const char * argv[])
{
 

    Fish* nemo = new Fish("Nemo");
    Fish* dory = new Fish("Dory");
    
    Cat* kitty = new Cat("Kitty");
    Dog* spot = new Dog("Spot");
    Beagle* max = new Beagle("Max");
    
      /* Let's print out their info with the function I declared at the top! Notice how the function takes Animals, yet we're passing in Dogs, Fish, Cats, etc.
    printAnimalInfo(nemo);
    printAnimalInfo(dory);
    printAnimalInfo(kitty);
    printAnimalInfo(spot);
    printAnimalInfo(max);
      */
    
    //The animals are casuing mischief!
    spot->chaseCat(kitty);
    kitty->eatAFish(nemo);
    kitty->eatAFish(dory);
    
    return 0;
}
开发者ID:FRCTeam1073-TheForceTeam,项目名称:preseason2012,代码行数:26,代码来源:AnimalDemo.cpp

示例8: main

int main () {
  // Cat and dog instantiations
  Cat cat_jc("Jean-Claude", 14);
  Cat cat_jp("Jean-Pierre", 9);
  Dog dog_h("Helios", 1);

  // Vector instantiation
  std::vector<Pet*> pets;

  // Insert cats and the dog into the vector
  pets.reserve(3);
  pets.push_back(&cat_jc);
  pets.push_back(&cat_jp);
  pets.push_back(&dog_h);

  for (std::vector<Pet*>::const_iterator pets_it = pets.begin(); pets_it != pets.end(); ++pets_it) {
    // Use the dynamic cast
    Cat *cat = dynamic_cast<Cat*>(*pets_it);
    Dog *dog = dynamic_cast<Dog*>(*pets_it);

    if (cat) {
      cat->pee("outside");
    }

    if (dog) {
      dog->pee("on the home's room floor");
      dog->vomit("on the home's kitchen floor");
    }
  }

  return 0;
}
开发者ID:reaper,项目名称:cplusplus-samples,代码行数:32,代码来源:main.cpp

示例9: main

int main()
{
    Shelter aq;
    Cat c1("Cat1");
    Cat c2("Cat2");
    Cat c3("Cat3");
    Dog d1("Dog1");
    Dog d2("Dog2");
    Dog d3("Dog3");

    aq.enqueue(d1);
    aq.enqueue(c1);
    aq.enqueue(c2);
    aq.enqueue(c3);
    aq.enqueue(d2);
    aq.enqueue(d3);

    Animal a = aq.dequeueAny();
    cout << "Get your pet: " << a.getName() << endl;
    Cat c = aq.dequeueCat();
    cout << "Get your cat: " << c.getName() << endl;
    Dog d = aq.dequeueDog();
    cout << "Get your dog: " << d.getName() << endl;
    return 0;
}
开发者ID:li--paul,项目名称:careercup150,代码行数:25,代码来源:03-07-dogs-and-cats.cpp

示例10: main

int main()
{
	Cat Tom;
    Tom.color = "blue"; // eroare: Cat::color este privat
    Tom.SetColor("blue and white"); // ok
	cout << Tom.GetColor();
    return 0;
}
开发者ID:Pudak,项目名称:cdl,代码行数:8,代码来源:access.cpp

示例11: main

int main()
{
	Cat c;
	Sound theSound;
	c.letsDo(&theSound);
	Dog d;
	d.letsDo(&theSound);
}
开发者ID:shashank-vishnoi,项目名称:my_project,代码行数:8,代码来源:visitor_animal_example.cpp

示例12: display

void Node::display()
{
	cout << "Name: " << itsCat->getName() << ", ";
	cout << "age: " << itsCat->getAge() << endl;

	if(itsNext)
		itsNext->display();			
}
开发者ID:trondbert,项目名称:MyKeep,代码行数:8,代码来源:Liste.cpp

示例13: main

int main()
{
  const Cat c;
  c.MakeSound();

  const Dog d;
  d.MakeSound();
}
开发者ID:RLED,项目名称:ProjectRichelBilderbeek,代码行数:8,代码来源:main.cpp

示例14: f11_2

void f11_2(){
   Cat frisky;
   frisky.SetAge(5);
   frisky.Meow();
   cout <<"cat age="
      <<frisky.GetAge()
      <<endl;
   frisky.Meow();
}
开发者ID:sjtusonic,项目名称:exe,代码行数:9,代码来源:11.2.cpp

示例15: main

int main(void)
{
	cout << "Test" << endl;
	Dog dog;
	dog.bark();

	Cat cat;
	cat.sayMiew();
}
开发者ID:jkatghub,项目名称:tud-cpp-lecture,代码行数:9,代码来源:main.cpp


注:本文中的Cat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。