Address-of operator on method

Hi there!
I'm making this class for handling sprites in DX10, and it hold this static ID3DX10Sprite * spriteObject, which I need to initialize with the function D3DX10CreateSprite(..., ..., ...). The spriteObject is private (Hiding data is a good thing, right? Otherwise I don't have a problem :P) and I (Try to) access it with a public GetSpriteObject() method. However, I need to use the address-of operator on it, and I don't understand how.

If I make the spriteObject public, it compiles if I pass &Sprite::spriteObject as an argument. But I want to use my GetSpriteObject() method, because I want to learn to write good code.


Here's some code where I've removed the irrelevant stuff for your viewing pleasure, and my problem. =)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Sprite
{
public:
	static ID3DX10Sprite * GetSpriteObject() { return spriteObject; }

private:
	static ID3DX10Sprite * spriteObject;
};

ID3DX10Sprite * Sprite::spriteObject = NULL;



// Somewhere else far far away =)
D3DX10CreateSprite(..., ..., &Sprite::GetSpriteObject()); // Does not work
D3DX10CreateSprite(..., ..., &Sprite::spriteObject); // Works if spriteObject is public 
> Hiding data is a good thing, right?

Not necessarily. If it hides implementation, or at least restricts access to it, it is usually a good thing.

1
2
3
4
5
6
7
8
9
10
11
12
class Sprite
{
    public:
        static ID3DX10Sprite** address_of_sprite_object() { return &spriteObject; }

    private:
        static ID3DX10Sprite * spriteObject;
};

// ...

D3DX10CreateSprite( ..., ..., Sprite::address_of_sprite_object() ) ;


But then, you might as well make it public - private is not hiding anything.
Topic archived. No new replies allowed.