Page 2 of 8

Re: New Gyromite

Posted: Tue Dec 30, 2008 1:15 am
by M_D_K
yes it will be 44 when the function ends.

Code: Select all

JSL::JSL()
{
        bran_flakes = 44; //its 44 I'm pretty sure
};
[...]

printf("OMG I have %f bran flakes\n", jsl->bran_flakes);

Re: New Gyromite

Posted: Tue Dec 30, 2008 2:39 am
by Arce
Jsl, how are you deducing that it doesn't work? Your example is done right, and it does work how you want...

Maybe it a problem elsewhere? Calling the wrong constructor or something...? Mind posting a code snippet and the output? I'm still not exactly sure what problem you have...

Also, if you find that you're using a bunch of statics, consider a singleton?

Hopefully this'll help some..

Code: Select all

class dildo {
     int member_A;         //Member data (private)
     string asswranger;    //Member data (private)
     public:
           dildo():member_A(44),asswrangler("twat") {std::cout << "def constr call";}
           ~dildo();

          
              //at the end of this func, x and y are out of scope, and asswrangler is "twathole"
              void func_A() {
                    int x,y;
                    x=y=0;
                    asswranger+="hole";
               }
              //at the end, x is out of scope and member_A=whatever the fuck you passed
              void func_B(int x) {
                     member_A=x;
               }
};
printf("OMG I have %f bran flakes\n", jsl->bran_flakes);
Also, bran_flakes is not a pointer, so you would use the dot operator (.) rather than the indirection operator (->)

Re: New Gyromite

Posted: Tue Dec 30, 2008 2:46 am
by M_D_K
Arce wrote:
printf("OMG I have %f bran flakes\n", jsl->bran_flakes);
Also, bran_flakes is not a pointer, so you would use the dot operator (.) rather than the indirection operator (->)
but jsl is...well at least in my version :)

Code: Select all

JSL *jsl = new JSL();
printf("OMG I have %f bran flakes\n", jsl->bran_flakes);

Re: New Gyromite

Posted: Tue Dec 30, 2008 3:59 pm
by JS Lemming

Code: Select all

class dildo {
     int member_A;         //Member data (private)
     public:
           dildo():member_A(44)
          {
                    std::cout << "member_A is " << member_A;
                    hey();
          }
           ~dildo();

          void hey() { member_A = 55; }

          void corn() { std::cout << "WTF is member_A? " << member_A; }
};
Calling corn() after creating an instance of dildo prints out that member_A is ZERO. That is my problem. I wish it were 55. It's only 55 if I make member_A static.

I don't think a singleton has anything to do with this but I could be wrong.

Re: New Gyromite

Posted: Tue Dec 30, 2008 4:15 pm
by M_D_K
well that code works for me. So I don't know WTF is going on there.

Re: New Gyromite

Posted: Tue Dec 30, 2008 4:23 pm
by Falco Girgis
Something must be seriously screwed up. That defies the laws of C++ and OO programming.

Re: New Gyromite

Posted: Tue Dec 30, 2008 4:37 pm
by Arce
That should work, so the problem obviously isn't in the actual class.

How're you creating an instance? Are you doing more crap with lists? Is it being screwed when you push and pop them?

Could you show us where you're creating an instance and where you're retrieving the value of member_A? Something sounds seriously fucked.

Also, why are you putting member_A in the initializer list if you're just setting it in the function body? The redundancy shouldn't be a problem, though...

Again, lessee how you initialize an object...If it's not calling your constructor, then maybe member_A is a random value, and your compiler shows 0 for Null? Eh, that's stretching...o.o;;;;

Re: New Gyromite

Posted: Tue Dec 30, 2008 7:08 pm
by JS Lemming
Holy fucking shit. I am theeeeee dumbest dumb shit alive. Wow. Woooooow.

Ok guys... Wow. Sooo it turns out I deleted the instance of the class right after I made the instance (for debugging purposes a few days ago) and had forgotten to remove the delete... And the fact that it still fucking worked (aside from this member variable abomination) when I called on functions in the no longer existing instance is why I didn't catch the delete till just now. Once again... Wow.

Lesson learned: If you delete your class instance C++ fucks your mother but doesn't tell you.

Re: New Gyromite

Posted: Tue Dec 30, 2008 7:22 pm
by Arce
Lesson learned: If you delete your class instance C++ fucks your mother but doesn't tell you.
:lol: :lol: :lol:
I rofled!

Re: New Gyromite

Posted: Tue Dec 30, 2008 7:23 pm
by Arce
Also, I like your neat little way of saving/loading shit. Looks pretty tight to see an ascii level. ;p

Re: New Gyromite

Posted: Tue Dec 30, 2008 7:30 pm
by dandymcgee
Don't worry.. It's always something stupid. Congrats on finding it though!

Re: New Gyromite

Posted: Tue Dec 30, 2008 7:49 pm
by JS Lemming
Thanks guys.
Arce wrote:Also, I like your neat little way of saving/loading shit. Looks pretty tight to see an ascii level. ;p
Haha yeah. Interpreting the ascii data is pretty ridiculous. Check out what it has to do when it sees a blue pipe "B"...

Code: Select all

	case 'B':
	mapt[x][y] = 0;
	xv=0; yv=0;
	if(mapt[x+1][y] == 'b') {
		xv=1; yv=0;
	} else if(mapt[x][y+1] == 'b') {
		xv=0; yv=1;
	} else if(mapt[x-1][y] == 'b') {
		xv=-1; yv=0;
	} else if(mapt[x][y-1] == 'b') {
		xv=0; yv=-1;
	}
	if(xv!=0)
	{
		for(i=1; ; i++)
		{
			map[x+((i-1)*xv)-1][y-1][1] = '.';
			if(mapt[x+(i*xv)][y] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, HORZ, x-1, y-1, x+((i-1)*xv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '+';
	}
	if(yv!=0)
	{
		for(i=1; ; i++)
		{
			map[x-1][y+((i-1)*yv)-1][1] = '.';
			if(mapt[x][y+(i*yv)] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, VERT, x-1, y-1, y+((i-1)*yv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '-';
	}
	break;

Re: New Gyromite

Posted: Tue Dec 30, 2008 8:45 pm
by M_D_K
JS Lemming wrote:Thanks guys.
Arce wrote:Also, I like your neat little way of saving/loading shit. Looks pretty tight to see an ascii level. ;p
Haha yeah. Interpreting the ascii data is pretty ridiculous. Check out what it has to do when it sees a blue pipe "B"...

Code: Select all

	case 'B':
	mapt[x][y] = 0;
	xv=0; yv=0;
	if(mapt[x+1][y] == 'b') {
		xv=1; yv=0;
	} else if(mapt[x][y+1] == 'b') {
		xv=0; yv=1;
	} else if(mapt[x-1][y] == 'b') {
		xv=-1; yv=0;
	} else if(mapt[x][y-1] == 'b') {
		xv=0; yv=-1;
	}
	if(xv!=0)
	{
		for(i=1; ; i++)
		{
			map[x+((i-1)*xv)-1][y-1][1] = '.';
			if(mapt[x+(i*xv)][y] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, HORZ, x-1, y-1, x+((i-1)*xv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '+';
	}
	if(yv!=0)
	{
		for(i=1; ; i++)
		{
			map[x-1][y+((i-1)*yv)-1][1] = '.';
			if(mapt[x][y+(i*yv)] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, VERT, x-1, y-1, y+((i-1)*yv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '-';
	}
	break;
Wow!! I bet if I read that I would understand all of it :)
JS Lemming wrote:Holy fucking shit. I am theeeeee dumbest dumb shit alive. Wow. Woooooow.

Ok guys... Wow. Sooo it turns out I deleted the instance of the class right after I made the instance (for debugging purposes a few days ago) and had forgotten to remove the delete... And the fact that it still fucking worked (aside from this member variable abomination) when I called on functions in the no longer existing instance is why I didn't catch the delete till just now. Once again... Wow.

Lesson learned: If you delete your class instance C++ fucks your mother but doesn't tell you.
:lol:

And using accessors in place of direct access to variables doesn't help :)

Re: New Gyromite

Posted: Tue Dec 30, 2008 10:26 pm
by dandymcgee
Your variable names make my head hurt. :shock:

Re: New Gyromite

Posted: Tue Dec 30, 2008 11:34 pm
by eatcomics
dandymcgee wrote:Your variable names make my head hurt. :shock:
That's were they lost me too... :shock: