Skip to content

Instantly share code, notes, and snippets.

@dwatanabee
Created June 27, 2022 07:57
Show Gist options
  • Save dwatanabee/06afc212885f630c6651da7add0f9d3f to your computer and use it in GitHub Desktop.
Save dwatanabee/06afc212885f630c6651da7add0f9d3f to your computer and use it in GitHub Desktop.
overrideテスト
#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