Skip to content

Instantly share code, notes, and snippets.

@yifu
Created September 21, 2012 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yifu/3762203 to your computer and use it in GitHub Desktop.
Save yifu/3762203 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <memory>
struct A
{
virtual void process();
};
struct B : public A
{
virtual void process();
};
void A::process() { std::cout << "A process" << std::endl; }
void B::process() { std::cout << "B process" << std::endl; }
typedef std::auto_ptr<B> (*func_def)();
std::auto_ptr<B> f()
{
return std::auto_ptr<B>(new B);
}
int main()
{
// f();
func_def func = f;
std::auto_ptr<A> test((*func)());
test->process();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment