Constructor is not expected to do much processing, generally, so I would steer clear of that at least.
Result
object should be just the result, created and returned by some other class (or just function, if you're interfacing C). Depending on how much stuff there will be in the result, you can construct that either with constructor parameters, or if there are too many, then having constructor with no parameters (or mandatory parameters), and then set all (or optional) parameters of Result
instance after construction, before returning it.
If the library->get_result(foo)
involves actual processing and not just getting current result value, then I'd use alternative name. At least to me "get" suggests it is a lightweight operation.
So, in this case probably one of these (C++11 assumed), first declaration of a function (C++ is multi-paradigm language, nothing wrong with functions especially when interfacing with C libs):
namespace library {
class Result {...}
std::unique_ptr<Result> process(library_handle*, foo*); // note: uses move semantics
}
//usage
auto result = library::process(handle, foo)
Also note how I removed "foo" from function name. C++ supports overloading, no point in duplicating information, which is already given by type of 2nd argument.
Or a more object-oriented approach:
namespace library {
class Result {...}
class Library {
Library(library_handle*); // constructor
std::unique_ptr<Result> process(foo*); // library handle already known
}
}
//usage
auto result = library->process(foo);
In that last example, result might also get stored as member variable in Library class, in which case you would have getter for it. Also, depending on who owns the Result and how big it is, you should consider passing it by value, after learning about C++11 move semantics which would avoid a lot fo copies.
General thoughts: if you are unsure about your C++, consider providing just a very thin C++ wrapper around C, basically just some convenience "value" classes like that Result
, and plain functions in a namespace, almost 1:1 mapping to your C API. It might not be as nice as a good OOP C++ API, but it will be a lot better than crappy C++ API designed while learning modern C++ ;)