Skip to content

Instantly share code, notes, and snippets.

@wngreene
Last active June 12, 2016 19:27
Show Gist options
  • Save wngreene/0d401abed67604c671b4f91ea3698a31 to your computer and use it in GitHub Desktop.
Save wngreene/0d401abed67604c671b4f91ea3698a31 to your computer and use it in GitHub Desktop.
Example of use of default specifier that fails to compile.
/**
* \brief Class to represent a feature track.
*/
class FeatureTrack final {
public:
explicit FeatureTrack(const uint32_t id = 0, const uint32_t img_idx = 0,
const cv::Point2f& feat = cv::Point2f()) :
id(id),
pos(1, feat),
img(1, img_idx) {}
~FeatureTrack() = default;
FeatureTrack(const FeatureTrack& rhs) = default;
FeatureTrack& operator=(const FeatureTrack& rhs) = default;
FeatureTrack(const FeatureTrack&& rhs) = default;
FeatureTrack& operator=(const FeatureTrack&& rhs) = default;
uint32_t id; // Track id.
std::vector<uint32_t> img; // Image indices.
std::vector<cv::Point2f> pos; // Feature positions.
};
@wngreene
Copy link
Author

wngreene commented Jun 4, 2016

Compiler output:

/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:27:3: error: defaulted declaration ‘depthest::FeatureTrack::FeatureTrack(const depthest::FeatureTrack&&)’
   FeatureTrack(const FeatureTrack&& rhs) = default;
   ^
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:27:3: error: does not match expected signature ‘depthest::FeatureTrack::FeatureTrack(depthest::FeatureTrack&&)’
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:28:17: error: defaulted declaration ‘depthest::FeatureTrack& depthest::FeatureTrack::operator=(const depthest::FeatureTrack&&)’
   FeatureTrack& operator=(const FeatureTrack&& rhs) = default;
                 ^
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:28:17: error: does not match expected signature ‘depthest::FeatureTrack& depthest::FeatureTrack::operator=(depthest::FeatureTrack&&)’
In file included from /home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_tracker.h:10:0,
                 from /home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/klt_feature_tracker.h:13,
                 from /home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/klt_feature_tracker.cc:3:
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:27:3: error: defaulted declaration ‘depthest::FeatureTrack::FeatureTrack(const depthest::FeatureTrack&&)’
   FeatureTrack(const FeatureTrack&& rhs) = default;
   ^
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:27:3: error: does not match expected signature ‘depthest::FeatureTrack::FeatureTrack(depthest::FeatureTrack&&)’
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:28:17: error: defaulted declaration ‘depthest::FeatureTrack& depthest::FeatureTrack::operator=(const depthest::FeatureTrack&&)’
   FeatureTrack& operator=(const FeatureTrack&& rhs) = default;
                 ^
/home/wng/Projects/rrg/rrg/src/perception/depthest/src/depthest/feature_track.h:28:17: error: does not match expected signature ‘depthest::FeatureTrack& depthest::FeatureTrack::operator=(depthest::FeatureTrack&&)’

@wngreene
Copy link
Author

For future reference this fails because the arguments to the move constructor and assignment operator are const (which doesn't make any sense given what they're supposed to do).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment