Let's say I want to make some sort of engine which should support loading graphical Image
s, so I have
struct Image;
Image* load_image_from_file(...);
I don't want external world to know what Image
really is, they'll deal only with pointers to it.
However inside engine
I want to use specific type, e.g. SDL_Surface
which is fully defined in SDL.
Can I somehow redifine Image for this file so compiler assumes SDL_Surface*
each time it sees Image*
(other than macro)?
I.e. I want something like typedef struct SDL_Surface Image;
All attempts like
using Image = SDL_Surface;
typedef SDL_Surface Image;
typedef struct SDL_Surface Image;
produce compile time error (http://codepad.org/1cFn18oh).
I know that I can use something like struct Image{SDL_Surface* surface};
in engine.c
/engine.cpp
but it creates unnecessary indirection and I'll have to type ->surface
.
Another dirty solution is to use explicit casts, e.g.((SDL_Surface*)image)
but I'm interesting in cleaner renaming.
PS. I'm interested in answers for both C and C++.