예제 #1
0
// 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();
}
int main() {
	cout << "Starting program...." << endl;
	{
		Cat bob;
		bob.speak();
	}
	cout << "Stopping program...." << endl;
	return 0;
}
예제 #3
0
파일: inher.cpp 프로젝트: dportok/gitcplus
int main () {
	cout << "Hello World" << endl;

	Animal a;
	a.speak();

    Cat cat;
    cat.speak();
    cat.jump();
	return 0;
}
예제 #4
0
파일: main.cpp 프로젝트: nllptr/EDAF30
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;
}