class array to list

Started by
11 comments, last by Absurdon 7 years, 9 months ago

it's in the same function:

std::list<Ausfaelle>Ausfalllinie[10];

for( int x = 0; x < 10; x = x + 1 )
{
Ausfalllinie[x].push_back(Ausfaelle(x,1,22,bremsen,mldgheight));

mldgheight =+30;
}

if (mldg == 0){
for( int x = 0; x < 10; x = x + 1 )
{
for (std::list<Ausfaelle>::iterator it=Ausfalllinie[x].begin(); it != Ausfalllinie[x].end(); ++it)
{
XPLMSetGraphicsState(0, 1, 0, 0, 1, 0, 0); // 1 texture and alpha blending
glPushMatrix();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
XPLMBindTexture2d(textures[AUSFALL1_TEXTURE].texIMGID, 0);
glColor3f(1, 1, 1);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(offx + 20, offy - 675 -mldgheight); //no idea on how to get the height from class
glTexCoord2i(0, 1);
glVertex2i(offx + 20, offy - 650-mldgheight);
glTexCoord2i(1, 1);
glVertex2i(offx + 120, offy - 650-mldgheight);
glTexCoord2i(1, 0);
glVertex2i(offx + 120, offy - 675-mldgheight);
glEnd();
glPopMatrix();
}

I'm new to classes in list etc. and try to save time while learning. Basically, for a start I want to display the image one below the other for the 10 list objects.

Many thanks

Advertisement
Again, your constructor does not do what you think it does. This has nothing to do with classes, this is the basics of value assignment in C++ (or even C).

I your constructor you have parameters a, b, c and d. Then you override whatever value was stored inside that with the following statements:


   a = index;
   b = active;
   c = color;
   d = drValue;

What you realy want to do is this:


  index = a;   // Sets member variable index value to whatever a is
  active = b;  // Sets member variable active value to whatever b is
  color = c;   // Sets member variable color value to whatever c is
  drValue = d; // Sets member variable drValue value to whatever d is 

so you basically do it the wrong way around. The same function as referred to by @[member='BitMaster'] would in this case be the constructor and as you posted it there is nothing else than setting those 4 values in it. Do you even know about variable scopes? If not you should check this out befor doing anything else.

Another thing is as you are doing it now you have an array of lists with each list containing only a single element making the list completly unneccessary. I assume there will be more in it later added dynamicaly otherwise you should realy clean that up. Learn about containers and what they are used for in that case.

In your comments you say you have no idea on how to get the value from the class. Is this because you don't know how to access members of classes? In earlier code you did this.

Ausfaelle test = *iter; if (test.drValue == 1){

Where is mldgheight comming from? Is it an attribute of Ausfaelle? If so what's its access modifier? Do you know about how access modifiers work? (That's the private, protected, public stuff)

I guess the function doing the drawing is not a member of Ausfaelle. By default in C++ everything in a class is private so it can't be accessed from outside of the class. Use access modifiers to change that behaviour.

As it looks for me at the moment you are missing some basic understanding of how classes work aswell on how containers work in C++. Do yourself a favour before coding more and read a bit into what a class is, what access modifiers are, how value assignments work and what a variable scope is in programming in general and C++. If you already know about these ignore this statement but it realy does not look like as if you realy understood how it works. No need to read a book on each of these things just some basic stuff. should be done in about 20 minutes.

This topic is closed to new replies.

Advertisement