1

When I try to simply initialize a std::vector of float[4] I get a C2440 compiler error. I have got this error message:

error C2440: return : cannot convert from float [4] to float (&&)[4]

C2440Exemple.h:

#pragma once

#include <iostream>
#include <vector>
#include <array>

class C2440Exemple
{
public:
    C2440Exemple();
    ~C2440Exemple();

private:
    std::vector<float[4]> normData;
};

C2440Exemple.cpp:

#include "stdafx.h"
#include "C2440Exemple.h"

C2440Exemple::C2440Exemple()
{
    normData = std::vector<float[4]>(); // error C2440
}

C2440Exemple::~C2440Exemple()
{
}

I was on this page, but don't get a total understanding about why I get C2440. Any ideas?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
sachaamm
  • 139
  • 2
  • 13
  • And also I don't know exactly what means float(&&) ??? It means float & ? – sachaamm Jan 17 '16 at 00:21
  • Ignoring for a moment your problem, your _solution_ is to use `std::vector>`. – ildjarn Jan 17 '16 at 00:27
  • Couldn't reproduce your problem on neither g++ nor clang. Maybe a compiler issue. What compiler are you using ? – hlscalon Jan 17 '16 at 00:30
  • @old_mountain : Illegal code doesn't always get the same diagnostics. And clang doesn't seem to like this much, nor should it: http://coliru.stacked-crooked.com/a/d4c2b3c536a09473 – ildjarn Jan 17 '16 at 00:37
  • Works in VS2015 Upd 1 – doug Jan 17 '16 at 00:40
  • Can anybody explain to me what means float(&&)[4] ? This requires a reference maybe ? – sachaamm Jan 17 '16 at 00:40
  • @ildjarn with default arguments I had no problems. http://coliru.stacked-crooked.com/a/ea8b4f02aad62adc – hlscalon Jan 17 '16 at 00:42
  • @old_mountain : As before, that is libstdc++ being lenient; a more conformant implementation complains: http://coliru.stacked-crooked.com/a/aaa1d90c60526446 – ildjarn Jan 17 '16 at 00:46

0 Answers0