0

I have some code, written on Linux, that i am attempting to compile in Windows, visual studio 2015.

In one of the Header files:

    #include <Eigen/Core>
    #include <Eigen/Geometry>
    #include <Eigen/StdVector>
    #include "transformable_vector.h"

    namespace nicp {

      template <int wCoordinate_>
        class HomogeneousVector4f : public Eigen::Vector4f {
      public:
        EIGEN_MAKE_ALIGNED_OPERATOR_NEW;

        static const float wCoordinate = wCoordinate_;

}

the lines:

 template <int wCoordinate_>
    class HomogeneousVector4f : public Eigen::Vector4f {
  public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW;

    static const float wCoordinate = wCoordinate_;

are giving me this error:

Error   C2864   'nicp::HomogeneousVector4f<0>::wCoordinate': a static data member with an in-class initializer must have non-volatile const integral type

I have tried removing the const, and replacing it with constexpr, but to the same result.

I have tried:

const float HomogeneousVector4f<wCoordinate_>::wCoordinate = wCoordinate_;

as well as:

 static constexpr float wCoordinate () { return wCoordinate_; }

and:

static float wCoordinate () { return wCoordinate_; }

EDIT: I have tried all the answers in the question marked as 'duplicate', to no avail. I believe the difference here is that this class is created with an int passed to it.

Thank you.

anti
  • 3,011
  • 7
  • 36
  • 86
  • Try adding "constexpr float HomogeneousVector4f:: wCoordinate;" to your .cpp file right after header include AND replace const with constexpr – Dmitrii Z. Mar 28 '17 at 11:46
  • Could you make a MCVE? I cannot reproduce with [this code](http://coliru.stacked-crooked.com/a/3a97548ff40b59f4) on MSVS 2015 or 2017. – NathanOliver Mar 28 '17 at 11:49
  • @DmitriiZ. I cannot add that under the includes, as the class is defined lower down. I have added more code to my question. Thanks! – anti Mar 28 '17 at 11:56
  • 1
    Since `wCoordinate` is not of an integral type you need to define/initialize it "out of class". Try putting `template const float HomogeneousVector4f::wCoordinate = wCoordinate_` *after* the class definition for `HomogeneousVector4f`. – G.M. Mar 28 '17 at 12:04
  • @G.M. thanks for your reply. I added this line, and see the same error. If I comment out `template `, intelsense complains – anti Mar 28 '17 at 12:14

0 Answers0