[ create a new paste ] login | about

Link: http://codepad.org/MNao3Q2P    [ raw code | output | fork ]

C++, pasted on Mar 24:
#include <iostream>
using std::cout;
using std::endl;

class monster {
	public:
	int x, y;
	float health;
	bool alive;
};

class boss {
	public:
	int x, y;
	float health;
	bool alive;
	int gold_drop;
};

typedef struct _uber_awesome_advanced_memory_simulating_struct_close_enough {
	monster m;
	boss b;
	monster* get_mp () {return &m;}
	boss* get_bp () {return &b;}
} uber;

int main () {
	uber ub;
	monster *m = ub.get_mp();
	boss *b = ub.get_bp();
	
	cout<<"m "<<m<<endl;
	cout<<"b "<<b<<endl;
	
	b->x = b->y = 123;
	m->x = m->y = 900;
	
	monster* bad_pointer;
	bad_pointer = m;
	cout<<"bad_p1 "<<bad_pointer<<endl;
	
	cout<<"OOOPS bad pointer management"<<endl;
	bad_pointer += 0x1;
	cout<<"bad_p2 "<<bad_pointer<<"\n\n"<<endl;
	
	
	cout<<"What is the MONSTER position?: ["<<bad_pointer->x<<", "<<bad_pointer->y
	<<"] ... WHAT?\n";
	cout<<"wait... wait... what? I'm out of here.";
	
}


Output:
1
2
3
4
5
6
7
8
9
m 0xffafb824
b 0xffafb834
bad_p1 0xffafb824
OOOPS bad pointer management
bad_p2 0xffafb834


What is the MONSTER position?: [123, 123] ... WHAT?
wait... wait... what? I'm out of here.


Create a new paste based on this one


Comments: