K
Kent
Hi!
I am working with an obscure graphics library in school as a university C++
programming project. The graphics library has a class kalled Bitmap wich you
use to draw graphics (you can "stamp it down" on the screen, double
buffering and such is all within the lib).
This is how it works now (i think its a bad design):
In a class i created to represent "monsters" in a game i have the following
method (se declaration on line below):
Bitmap* getBitmap(void); // returns the pointer i store localy
The class has a variable wich points to an instance of a Bitmap (se line
below):
Bitmap* bitmappointer; // Points to the picture of the monster
I need to return the bitmappointer in order to be able to draw it (wich is
handled by another method), but when i give out the bitmap pointer something
outside my class instance could modify it and make it corrupt or destroy it.
So, i am wonder how i should solve this? Can i return a "constant reference"
instead so that the data stored at the pointer position couldn´t be harmed
by accident? And if so, how do i implement it? (in other words, what does
the return look like)
That was all, hope that i described my problem in enough detail for you to
understand it. And that you managed to look past my grammatical errors and
typos (as english isn´t my native language i can just do my best)
Best regards and many thanks in advance! / Kent
I am working with an obscure graphics library in school as a university C++
programming project. The graphics library has a class kalled Bitmap wich you
use to draw graphics (you can "stamp it down" on the screen, double
buffering and such is all within the lib).
This is how it works now (i think its a bad design):
In a class i created to represent "monsters" in a game i have the following
method (se declaration on line below):
Bitmap* getBitmap(void); // returns the pointer i store localy
The class has a variable wich points to an instance of a Bitmap (se line
below):
Bitmap* bitmappointer; // Points to the picture of the monster
I need to return the bitmappointer in order to be able to draw it (wich is
handled by another method), but when i give out the bitmap pointer something
outside my class instance could modify it and make it corrupt or destroy it.
So, i am wonder how i should solve this? Can i return a "constant reference"
instead so that the data stored at the pointer position couldn´t be harmed
by accident? And if so, how do i implement it? (in other words, what does
the return look like)
That was all, hope that i described my problem in enough detail for you to
understand it. And that you managed to look past my grammatical errors and
typos (as english isn´t my native language i can just do my best)
Best regards and many thanks in advance! / Kent