Question

I want to design an API, which internally uses EIGEN.

Based on http://eigen.tuxfamily.org/dox/TopicPassingByValue.html, if a class have a Eigen object as member, it can not be passed by value.

Is there any straight forward way to tell compiler (e.g. g++) the my object can not be passed by value?

Was it helpful?

Solution

You can simply make the copy constructor unavailable. You can achieve this by using Boost and inheriting from boost::noncopyable, or by making the copy constructor private:

struct Foo
{
private:
    Foo(Foo const &) { }
};

Or in the new C++ by explicitly deleting it:

struct Foo
{
    Foo(Foo const &) = delete;
    Foo(Foo &&)      = delete;
};

You should probably also make your class unassignable by doing the same to the assignment operator (and boost::noncopyable takes care of this for you).

OTHER TIPS

To prevent a C++ object from being copied, declare a copy constructor and assignment operator, but make those functions private. (Since they are not called by anything, you don't have to bother implementing them.)

The documentation you cited looks bogus. How is it that this Eigen::Vector2d object is able to achieve its proper alignment in the original object, and why wouldn't the copy object have the same alignment?

The extraordinary piece of information required for that to make sense is not given.

Just make a copy constructor/copy operator private.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top