#include <iostream>
#include <memory>
using namespace std;
struct A;
struct B;
struct Base {
	int y;
	static std::unique_ptr<Base> create( size_t n );
    virtual ~Base() { }
};
struct A : public Base {int a; virtual ~A(){};};
struct B : public Base {int b; virtual ~B(){};};

std::unique_ptr<Base> Base::create( size_t n ){
  	if( n == 1 ) return  std::unique_ptr<Base>(new A );
     else  return  std::unique_ptr<Base>(new B );
}

int main() {
	auto x = static_cast<A*>( Base::create(1).get() );
	x->y=1;
	x->a=2;
	return 0;
}