Created
June 27, 2022 07:57
-
-
Save dwatanabee/06afc212885f630c6651da7add0f9d3f to your computer and use it in GitHub Desktop.
overrideテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <memory> | |
#include <string> | |
class MeshBase | |
{ | |
public: | |
virtual ~MeshBase() {} | |
virtual void setParameter() = 0; | |
// | |
//その他共通のインターフェース | |
// | |
}; | |
class MeshICARAT : public MeshBase | |
{ | |
public: | |
MeshICARAT() {} | |
void setParameter() override { std::cout << "MeshICARAT クラス\n"; } | |
}; | |
class MeshVTK : public MeshBase | |
{ | |
public: | |
MeshVTK() {} | |
void setParameter() override { std::cout << "MeshVTK クラス\n"; } | |
}; | |
int main(int argc, char *argv[]) | |
{ | |
std::unique_ptr<MeshBase> mesh; | |
if(argc == 2) | |
{ | |
mesh = std::make_unique<MeshICARAT>(); | |
} | |
else if(argc == 3) | |
{ | |
mesh = std::make_unique<MeshVTK>(); | |
} | |
else | |
{ | |
std::cerr << "error" << std::endl; | |
exit(1); | |
} | |
mesh->setParameter(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment