Hey,

My code was working great yesterday. I go to submit it and it's got this new error out of nowhere! It is 'class std::vector<long double>' has no member named '_'. It says instantiated from the line

vector <LD> matrix;

and then takes me to some code entitled stl_vector.h. it points me to this

if (this->_._M_finish != this->_M_impl._M_end_of_storage)
	  {
	    this->_M_impl.construct(this->_M_impl._M_finish, __x);
	    ++this->_M_impl._M_finish;
	  }
	else
	  _M_insert_aux(end(), __x);
      }

I have no idea what is going on! Why is this happening?? It was all ready to go. Please help!
Thank you

Edited 5 Years Ago by megaLU: n/a

I typedef it before the class declaration and after namespace std;
But the error came up before i'd typedef'd it and hasn't changed since i've typedef'd it.

I think you need to post the entire code, maybe you did something a little weird that upset the compiler. Otherwise, this shouldn't cause an error.

Ok i've attached it. Thank you.

Attachments
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;



int main()
	{
/*int sum = 0;
for (int n =1; n<= 10; n++)
{
    sum += 2*n;
}
cout << "sum with for loop =" << sum<< endl;

int i=1;
int sum2 = 0;
while (i<=10)
{
    sum2 += 2*i;
    i++;
}
cout << "sum with while =" << sum2;*/


/*int chi_x;
for (int i=-10; i<=10; i++)
{
    if (i%2==0)
        {chi_x = 1;}
    else
        {chi_x = -1;}


    cout << "chi(" << i << ")=" << chi_x<< '\t';
}*/

/*int n;
int n_n;
cout << "please enter an integer n:";
cin >> n;
if (n%6==0)
    {
        n_n=2;
    }
else if ((n%2==0) || (n%3==0))
    {
        n_n=1;
    }
else
    {
        n_n=0;
    }
    cout << n_n;
	return 0;

	long double x=0;
	bool flag = true;
	while (flag)
	{cout << "Please enter a real number between 1 and -1: "
	cin >> x
	if ((x<-1) || (x>1))
	cout << "Domain error: x should be in [1, -1] \n Try again";
	else
        flag=false;}
        cout << "\\sin^{-1}(" << x << ")=" << asin(x) << endl;
	}*/

        vector <int> int_vect;
        int_vect.push_back(10);
        cout << "the value of the variable in the first position of the vector is"
        << int_vect[0] << endl;

        for (int i=1; i<=200; i++)
            {if (i%10 == 0)
            int_vect.push_back(i);}

        cout << "the value of the variable in the 10th position of the vector is"
        << int_vect[9] << endl;

        cout << int_vect.size();
        for (int i=0; i<=21; i++)
        cout <<"This vector is " << int_vect[i]<<endl;
        return 0;
        }

Now that is weird. That is not my code. Something has happened, possibly because of the error or possibly because of me, one second.

ok this should be it.

Attachments
#include <iostream>
#include <cmath>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>

using namespace std;

typedef long double LD;

class IFS
{


    public:
        IFS();
        IFS(const LD&, const LD&, const LD&,
            const LD&, const LD&, const LD&,
            const LD&, const LD&, const LD&);

        bool is_valid() const; //valid object?

        LD set_A (int, const LD&);
		LD get_A (LD)const;
		void eval(vector<LD>&, vector<LD>&);

    private:
    vector <LD> matrix;
            bool valid;
};

ostream& operator<<(ostream&, const IFS&);
IFS operator*(const IFS&, vector<int>);
IFS operator*(const IFS&, const IFS&);
IFS operator+(const IFS&, const IFS&);
IFS operator-(const IFS&, const IFS&);
/****************************************************************************
	The various member functions
****************************************************************************/

int main ()
{
    /* //tests
    IFS f(0.0, 1.0, 2.0, 0.0, 3.0, 2.0, 0.0, 0.0, 1.0);
    cout << f << endl;
    if(f.is_valid())
        cout << "f(x) is a valid object." << endl;
    else
        cout << "f(x) is not valid" << endl; */


        std::vector<LD> a(1);
        a[0] = 0.0;
        std::vector<LD> b(1);
        b[0] = 0.0;


        /*sierpinski triangle/*
        /*IFS f_1(0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 1.0);
        IFS f_2(0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.0, 1.0);
        IFS f_3(0.5, 0.0, 0.25, 0.0, 0.5, 0.4, 0.0, 0.0, 1.0);

        srand((unsigned)time(0));
        int number ;

        int k;
        cout << "Please enter the number of transformations desired: ";
        cin >> k;


        for (int j=1; j<=k; j++)
        {
            number = rand()%3+1;


        if (number == 1)
        {
            f_1.eval(a, b);}

        else if (number == 2)
        {
            f_2.eval(a, b);}

        else
        {
            f_3.eval(a, b);}

        cout <<  a[j] <<  '\t' << b[j] << endl;
        } */

        /*fern*/
        /*
        IFS f_1(0.14, 0.01, -0.08, 0.0, 0.51, -1.31, 0.0, 0.0, 1.0);
        IFS f_2(0.43, 0.52, 1.49, -0.45, 0.5, -0.75, 0.0, 0.0, 1.0);
        IFS f_3(0.45, -0.49, -1.62, 0.47, 0.47, -0.75, 0.0, 0.0, 1.0);
        IFS f_4(0.49, 0.0, 0.02, 0.0, 0.51, 1.62, 0.0, 0.0, 1.0);

        srand((unsigned)time(0));
        int number ;

        int k;
        cout << "Please enter the number of transformations required: ";
        cin >> k;


        for (int j=1; j<=k; j++)
        {
            number = rand()%100+1;


        if (number<= 10)
        {
            f_1.eval(a, b);}

        else if ((number >10) && (number<=45))
        {
            f_2.eval(a, b);}

        else if ((number>45) && (number<=70))
        {
            f_3.eval(a, b);}
        else
        {
            f_4.eval(a, b);
        }

        cout <<  a[j] <<  '\t' << b[j] << endl;
        }
        */


        /*spleenwortfern*/
        IFS f_1(0.0, 0.00, 0.00, 0.0, 0.16, 0.0, 0.0, 0.0, 1.0);
        IFS f_2(0.85, 0.04, 0.0, -0.04, 0.85, 1.6, 0.0, 0.0, 1.0);
        IFS f_3(0.2, -0.26, 0, 0.23, 0.22, 1.6, 0.0, 0.0, 1.0);
        IFS f_4(-0.15, 0.28, 0.0, 0.26, 0.24, 0.44, 0.0, 0.0, 1.0);


        srand((unsigned)time(0));
        int number ;

        int k;
        cout << "Please enter the number of transformations desired:";
        cin >> k;
        for (int j=1; j<=k; j++)
        {
            number = rand()%100+1;


        if (number<= 10)
        {
            f_1.eval(a, b);}

        else if ((number >10) && (number<=85))
        {
            f_2.eval(a, b);}

        else if ((number>85) && (number<=92))
        {
            f_3.eval(a, b);}
        else
        {
            f_4.eval(a, b);
        }

        cout <<  a[j] <<  '\t' << b[j] << endl;
        }



return 0;
}

// Constructors

IFS::IFS()
	{
	// No argument constructor
        matrix.push_back(1.0);
        matrix.push_back(0.0);
        matrix.push_back(0.0);
        matrix.push_back(0.0);
        matrix.push_back(1.0);
        matrix.push_back(0.0);
        matrix.push_back(0.0);
        matrix.push_back(0.0);
        matrix.push_back(1.0);

	}

IFS::IFS(const LD& xx, const LD& xy, const LD& xz, const LD& yx, const LD& yy, const LD& yz,
         const LD& zx, const LD& zy, const LD& zz)
	{
	// Nine argument constructor
	matrix.push_back(xx);
	matrix.push_back(xy);
	matrix.push_back(xz);
	matrix.push_back(yx);
	matrix.push_back(yy);
	matrix.push_back(yz);
	matrix.push_back(zx);
	matrix.push_back(zy);
	matrix.push_back(zz);

	if (zx!=0 || zy!=0 || zz!=1)
        valid = false;

	}
bool IFS::is_valid()const
    {
        return valid;
    }

LD IFS::set_A(int A, const LD& m)
{
    if (A<0 || A>8) //ensure A is valid
        A=A%9;
    matrix[A]=m;

    if (matrix[6]!=0 || matrix[7]!=0 || matrix[8]!=1)
        valid = false;
    else
        valid = true;
}
LD IFS::get_A(LD A)const
{
    return matrix[A];
}

ostream& operator<<(ostream& os, const IFS& f)
	{

        os << f.get_A(0) << " " << f.get_A(1)<< " " << f.get_A(2) << '\n' << f.get_A(3) << " " << f.get_A(4) << " "
        << f.get_A(5) << '\n' << f.get_A(6) << " " << f.get_A(7) << " "<< f.get_A(8)<< "  X";

	return os;

	}

void IFS::eval(vector<LD>&a, vector<LD>&b) // to find product of 3x3 matrix and (x,y,1)
{

    int m = a.size() - 1;

    a.push_back(matrix[0]*a[m] + matrix[1]*b[m] + matrix[2]);
    b.push_back(matrix[3]*a[m] + matrix[4]*b[m] + matrix[5]);

}

// The next three constructors are not necessary for the transformations performed here.
// However, there is potential to generate new interesting fractals by using products of affine transformations etc.

IFS operator*(const IFS& f, const IFS& g)
{
    int xx = f.get_A(0)*g.get_A(0) + f.get_A(1)*g.get_A(3) + f.get_A(2)*g.get_A(6);
    int xy = f.get_A(0)*g.get_A(1) + f.get_A(1)*g.get_A(4) + f.get_A(2)*g.get_A(7);
    int xz = f.get_A(0)*g.get_A(2) + f.get_A(1)*g.get_A(5) + f.get_A(2)*g.get_A(8);
    int yx = f.get_A(3)*g.get_A(0) + f.get_A(4)*g.get_A(3) + f.get_A(5)*g.get_A(6);
    int yy = f.get_A(3)*g.get_A(1) + f.get_A(4)*g.get_A(4) + f.get_A(5)*g.get_A(7);
    int yz = f.get_A(3)*g.get_A(2) + f.get_A(4)*g.get_A(5) + f.get_A(5)*g.get_A(8);
    int zx = f.get_A(6)*g.get_A(0) + f.get_A(7)*g.get_A(3) + f.get_A(8)*g.get_A(6);
    int zy = f.get_A(6)*g.get_A(1) + f.get_A(7)*g.get_A(4) + f.get_A(8)*g.get_A(7);
    int zz = f.get_A(6)*g.get_A(2) + f.get_A(7)*g.get_A(5) + f.get_A(8)*g.get_A(8);

    return IFS(xx,xy,xz,yx,yy,yz,zx,zy,zz);
}
IFS operator+(const IFS& f, const IFS& g)
{
    int xx = f.get_A(0)+g.get_A(0);
    int xy = f.get_A(1)+g.get_A(1);
    int xz = f.get_A(2)+g.get_A(2);
    int yx = f.get_A(3)+g.get_A(3);
    int yy = f.get_A(4)+g.get_A(4);
    int yz = f.get_A(5)+g.get_A(5);
    int zx = f.get_A(6)+g.get_A(6);
    int zy = f.get_A(7)+g.get_A(7);
    int zz = f.get_A(8)+g.get_A(8);

    return IFS(xx,xy,xz,yx,yy,yz,zx,zy,zz);
}

IFS operator-(const IFS& f, const IFS& g)
{
    int xx = f.get_A(0)-g.get_A(0);
    int xy = f.get_A(1)-g.get_A(1);
    int xz = f.get_A(2)-g.get_A(2);
    int yx = f.get_A(3)-g.get_A(3);
    int yy = f.get_A(4)-g.get_A(4);
    int yz = f.get_A(5)-g.get_A(5);
    int zx = f.get_A(6)-g.get_A(6);
    int zy = f.get_A(7)-g.get_A(7);
    int zz = f.get_A(8)-g.get_A(8);

    return IFS(xx,xy,xz,yx,yy,yz,zx,zy,zz);

}

Line 228

LD IFS::get_A(LD A)const
{
    return matrix[A];
}

You shouldn't have a long double as an index of a vector.

(there are a fair number of other warnings as well, which you should address)

partymild1.cpp:59:30: warning: "/*" within comment
partymild1.cpp:60:9: warning: "/*" within comment
partymild1.cpp: In member function `LD IFS::set_A(int, const LD&)':
partymild1.cpp:225: warning: control reaches end of non-void function
partymild1.cpp: In member function `LD IFS::get_A(LD) const':
partymild1.cpp:228: warning: passing `LD' for converting 1 of `typename _Alloc::
const_reference std::vector<_Tp, _Alloc>::operator[](size_t) const [with _Tp = L
D, _Alloc = std::allocator<LD>]'
partymild1.cpp: In function `IFS operator*(const IFS&, const IFS&)':
partymild1.cpp:256: warning: converting to `int' from `LD'
partymild1.cpp:257: warning: converting to `int' from `LD'
partymild1.cpp:258: warning: converting to `int' from `LD'
partymild1.cpp:259: warning: converting to `int' from `LD'
partymild1.cpp:260: warning: converting to `int' from `LD'
partymild1.cpp:261: warning: converting to `int' from `LD'
partymild1.cpp:262: warning: converting to `int' from `LD'
partymild1.cpp:263: warning: converting to `int' from `LD'
partymild1.cpp:264: warning: converting to `int' from `LD'
partymild1.cpp: In function `IFS operator+(const IFS&, const IFS&)':
partymild1.cpp:270: warning: converting to `int' from `LD'
partymild1.cpp:271: warning: converting to `int' from `LD'
partymild1.cpp:272: warning: converting to `int' from `LD'
partymild1.cpp:273: warning: converting to `int' from `LD'
partymild1.cpp:274: warning: converting to `int' from `LD'
partymild1.cpp:275: warning: converting to `int' from `LD'
partymild1.cpp:276: warning: converting to `int' from `LD'
partymild1.cpp:277: warning: converting to `int' from `LD'
partymild1.cpp:278: warning: converting to `int' from `LD'
partymild1.cpp: In function `IFS operator-(const IFS&, const IFS&)':
partymild1.cpp:285: warning: converting to `int' from `LD'
partymild1.cpp:286: warning: converting to `int' from `LD'
partymild1.cpp:287: warning: converting to `int' from `LD'
partymild1.cpp:288: warning: converting to `int' from `LD'
partymild1.cpp:289: warning: converting to `int' from `LD'
partymild1.cpp:290: warning: converting to `int' from `LD'
partymild1.cpp:291: warning: converting to `int' from `LD'
partymild1.cpp:292: warning: converting to `int' from `LD'
partymild1.cpp:293: warning: converting to `int' from `LD'

The first two are minor (nested comments) but you should investigate the rest too. These were found by compiling with the maximum warning level.

Edited 5 Years Ago by jonsca: n/a

Why yes of course, thank you. I have changed that back to int. Unfortunately the error was there before i accidentally changed it when typedefing, and so it is still there now i've changed it back. Thanks for pointing that out though.

Edited 5 Years Ago by megaLU: n/a

Oh wow, there are a lot of errors, huh? I think i've fixed some of the converting int to LD. How exactly is it you put on the maximum warning level so I can check? Thank you.

I'm not sure then, I'm not getting any error like that. Which compiler are you using? Sounds like Visual C++ if it's letting you step into the STL like that. Look and see if it's a known problem... otherwise, start a fresh program with just a vector initialized in it and see what happens.

I'm using code::blocks and g++. I now also get this error, does this shed any light?

'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = long double, _Alloc = std::allocator<long double>, value_type = long double]':|

Oh wow, there are a lot of errors, huh? I think i've fixed some of the converting int to LD. How exactly is it you put on the maximum warning level so I can check? Thank you.

Under:
project menu/<your proj name>properties/configurationproperties/CC++/warninglevel, change it to /W4

The only error I get when I compile it in VS (which only gives a warning in g++, oddly enough) is that you don't return a value from Set_A, which should be void anyway (or since you're doing some tests in it should return a bool)

Edited 5 Years Ago by jonsca: n/a

Thanks. I think that I changed something when i exited codeblocks last, when it asked me if i wanted to save some changes (not to file). Because the old file actually still compiles. Any changes, even when they're good like changing the matrix index to int stops it from compiling. At least I'm hoping that may be the problem. Thanks for your help.

Yeah I noticed the void too and tried to change it but it just stops it from compiling. Lame.

Edited 5 Years Ago by megaLU: n/a

Sorry, I didn't know you were using C::B, in that system to get the -Wall (assuming you use it with the gcc) it's under Project/ProjectBuildOptions/CompilerSettingsTab/CompilerFlags and Enable all compiler warnings should be checked.

Yeah I noticed the void too and tried to change it but it just stops it from compiling. Lame.

Just because it compiles doesn't mean it's correct lol. You probably didn't change it in both the declaration and the definition.

Edited 5 Years Ago by jonsca: n/a

No i did. In fact I tried changing just the filename and even that stops it compiling.

This article has been dead for over six months. Start a new discussion instead.