Possible Duplicate:
When to return a pointer, scalar and reference in C++?
Hi,
In example 1. I don't know what to use. Sample
should be returned as pointer or reference or like it is. Next, in example 2. GetSample
is used to retrieve Sample object and pushed on queue. I don't know here if should i use std::dequeue<Sample*>
. I see that object sample was copied 2 times (when returned from GetSample
and when was pushed on queue).
How should it be if speed is not so important. I'am interested in best practice.
// 1.
Sample GetSample()
{
Sample sample;
// fill sample
return sample;
}
// 2.
class AAA
{
void MakeSomethingWithSample()
{
Sample sample = GetSample();
samples.push(sample);
}
std::dequeue<Sample> samples;
};
class Sample
{
public:
Sample(void);
~Sample(void);
boost::optional<std::wstring> window_caption_;
boost::optional<std::wstring> image_fs_name_,
image_full_path_,
resource_image_name_;
boost::optional<boost::posix_time::ptime> probe_time_;
HWND window_handle_;
};