I like to be more standard as possible, so why should I \"constrain\" my classes defining it\'s members as OpenGL types when I can use primitive types? Is there any advantag
The advantages has already been mentioned here. However, there is a disadvantage clear from the following examples:
class FileIn
{
public:
//Public interface like read
private:
void* handle;
};
The above code fits very well in a platform independent header but writing
#define WIN32_LEAN_AND_MEAN
#include
class FileIn
{
public:
//Public interface like read
private:
HANDLE handle;
};
does not.
Though the former will require ugly typecasts like
int fd=(int)( (size_t)handle );
close(fd);
i do not know any system which have sizeof(void*)
< sizeof(int)
. Yes it will fail if open returns a negative number for a valid file handle.
What to learn about this? Avoid using typedefs in library include files. Instead use struct declarations even though C programmers need to write struct
a dozen times. Here, some C standard library implementations do it all wrong.
In stdio.h
:
struct FILE;
And in the application:
struct FILE* the_file=fopen("filename.txt","rb");
/*...*/
In stdio.h
:
typedef struct SOMENAMETHATNOONESHOULDUSE
{
/* Internal data members */
} FILE;
In application
FILE* the_file=fopen("filename.txt","rb");
When writing a C++ wrapper, this forces either #include
or simply declare the handle as above.