Original Post
Hi! I'm having a little problem getting the address memory of an array of floats. Take a look at the code: As you can see, C_TextSimple ctor calls C_TextManager's BuildFont, passing the charWidth pointer (and I want it to point at C_TextFont's array of widths). Inside C_TextManager::buildFont, charWidth receives the correct array address (0x014085f0), but when the execution flow returns to C_TextSimple ctor, charWidth is reseted again to its initial address (0xbaadf00d). Can you point me what's wrong? Thanks (and sorry for the bad English)!!!
// Simple text object
class C_TextSimple : public C_TextBase {
private:
GLuint listBase;
float* charWidth;
};
C_TextSimple::C_TextSimple( const char* fontName, int size ) {
listBase = BuildFont( fontName, size , charWidth ); // charWidth = 0xbaadf00d
}
// Font object
class C_TextFont {
private:
float charWidth[128];
public:
float* getWidths();
};
float* C_TextFont::getWidths() {
return charWidth;
}
// Text manager singleton
#define BuildFont C_TextManager::getInstance().buildFont
class C_TextManager {
private:
public:
unsigned int buildFont( const char*, int, float* ); // Build font
};
unsigned int C_TextManager::buildFont( const char* fontName, int fontHeight, float* charWidth ) {
C_TextFont newFont( library, fontName, fontHeight );
fontVector.push_back( newFont );
charWidth = fontVector.back().getWidths(); // charWidth = 0x014085f0 (OK, it is what I want)
...
}