mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
50 lines
875 B
C++
50 lines
875 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2016-2021 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** polymorphic1.cxx : example
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <iostream>
|
|
using std::cin;
|
|
using std::cout;
|
|
|
|
#include <vector>
|
|
using std::vector;
|
|
|
|
class lib {
|
|
public:
|
|
virtual int give() = 0;
|
|
};
|
|
class lib1 : lib {
|
|
public:
|
|
lib1() {};
|
|
int give() { return 1; };
|
|
};
|
|
class lib2 : lib {
|
|
public:
|
|
lib2() {};
|
|
int give() { return 2; };
|
|
};
|
|
|
|
int main() {
|
|
|
|
{
|
|
lib1 mylib;
|
|
cout << mylib.give() << '\n';
|
|
}
|
|
|
|
#if 0
|
|
{
|
|
// DOES NOT COMPILE: cannot create variable of abstract class
|
|
lib mylib = lib1();
|
|
cout << mylib.give() << '\n';
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|