Original Post
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<float[2]> t;
float* j[2];
j[0] = new float;
j[1] = new float;
*j[0] = 2;
*j[1] = 1;
t.push_back(j); //Error
return 0;
}
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<float[2]> t;
float* j[2];
j[0] = new float;
j[1] = new float;
*j[0] = 2;
*j[1] = 1;
t.push_back(j); //Error
return 0;
}
#include <vector>#include <iostream>#include <boost/array.hpp>using namespace std;using boost::array;int main(){ vector< array< float *, 2 > > t; array< float *, 2 > j; j[0] = new float; j[1] = new float; *j[0] = 2; *j[1] = 1; t.push_back(j); //Error return 0;}Quote:
Original post by Ezbez
IIRC, you have to explicitly cast to const. You can use const_cast<> for this. Google it if you want more information.
class FloatPair { float f[2]; float& operator[](const size_t& s) { return f[s]; } const float& operator[](const size_t& s) const { return f[s]; }};vector<FloatPair> t;// create itvector<float*> bigarray;float *smallarray1 = new float[2];float *smallarray2 = new float[2];bigarray.push_back(smallarray1);bigarray.push_back(smallarray2);// then clean it upfor (int i = 0; i < (int)bigarray.size(); i += 1){ if (bigarray.at(i) != NULL) { delete[] bigarray.at(i); }}
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more