Problem with Pointers April 19, 2012 07:24PM | Registered: 12 years ago Posts: 2 |
class Test : public Drawable{ private: int* pCounter; int debugHeight; public: Test(int debugHeight, int* pCounter); virtual void draw(); };
#include "Test.h" Test::Test(int debugHeight_, int * pCounter_) { pCounter = pCounter_; debugHeight = debugHeight_; } void Test::draw() { ++*pCounter; GRRLIB_Printf(30, debugHeight, tex_BMfont5, GRRLIB_WHITE, 1, "pCounter : %i", pCounter); GRRLIB_Printf(30, debugHeight + 20, tex_BMfont5, GRRLIB_WHITE, 1, "*pCounter : %i", *pCounter); }
void drawScreen(Screen screen) { std::maplMap = screen.getData(); std::map ::iterator layerIt; for (layerIt = lMap.begin(); layerIt != lMap.end(); layerIt++) { Layer lp = layerIt->second; std::map ::iterator drawIt; std::map dMap = lp.getData(); for (drawIt = dMap.begin(); drawIt != dMap.end(); drawIt++) { Drawable* dp = drawIt->second; dp->invokeAction(); dp->draw(); } } }
Screen screen2; Layer layer2; Drawable* test2 = new Test(400, pX); layer2.addDrawable(1, test2); screen2.addLayer(1, layer2);
class ScreenFact{ public: ScreenFact(); Screen getScreen(); };ScreenFact.cpp
ScreenFact::ScreenFact() { } Screen ScreenFact::getScreen() { int x = 10; int* pX = &x; Screen screen; Layer l; Drawable * t = new Test(300, pX); l.addDrawable(1, t); screen.addLayer(1, l); return screen; }
ScreenFact sf; Screen s = sf.getScreen();
Re: Problem with Pointers April 20, 2012 02:05AM | Moderator Registered: 14 years ago Posts: 686 |
Re: Problem with Pointers April 20, 2012 11:54AM | Registered: 12 years ago Posts: 2 |
Re: Problem with Pointers April 20, 2012 01:51PM | Registered: 13 years ago Posts: 363 |