A
Andrew Tomazos
Suppose I have a C interface as follows:
// create a new FOO
FOO* foo_open(int params);
// use FOO one or more times
void foo_bar(FOO*);
// destroy FOO
foo_close(FOO*);
and I want to wrap that in a C++11 class.
class Foo
{
Foo(int params) : p(foo_open(params)) {}
void bar() { foo_bar(p); }
~Foo() { if (p) { foo_close(p); } }
private:
FOO* p;
// Clearly Foo cannot be copied otherwise you will call foo_close
twice for the same handle
Foo(const Foo&) = delete;
Foo& operator= (const Foo&) = delete;
// But we should be able to move it
Foo(Foo&& that)
{
???
}
Foo& operator= (Foo&&)
{
???
}
};
I am not clear how to implement the move constructor and move
assignment. ? What role does std::move play if any in this case?
-Andrew.
// create a new FOO
FOO* foo_open(int params);
// use FOO one or more times
void foo_bar(FOO*);
// destroy FOO
foo_close(FOO*);
and I want to wrap that in a C++11 class.
class Foo
{
Foo(int params) : p(foo_open(params)) {}
void bar() { foo_bar(p); }
~Foo() { if (p) { foo_close(p); } }
private:
FOO* p;
// Clearly Foo cannot be copied otherwise you will call foo_close
twice for the same handle
Foo(const Foo&) = delete;
Foo& operator= (const Foo&) = delete;
// But we should be able to move it
Foo(Foo&& that)
{
???
}
Foo& operator= (Foo&&)
{
???
}
};
I am not clear how to implement the move constructor and move
assignment. ? What role does std::move play if any in this case?
-Andrew.