吧里的哥哥姐姐们帮忙看一下代码
[code=C/C++][/code]#ifndef__EXAMPLE_H__ //这个名称是为了防止重复定义,是定义:__EXAMPLE_H__ 为#include一直到#endif前的内容
#define__EXAMPLE_H__
#include ...
class Example:GL_Application
{
public:
//
private:
//
};
#endif
///这是另一个项目里的内容
LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
.......
if (msg==WM_CREATE)
{
CREATESTRUCT* creation=reinterpret_cast<CREATESTRUCT*>(lparam);
//上面这一行解释的是:返回窗口结构的指针,它保存刚创建的程序实例的类
//reinterpret_cast<>()是什么语法?
GL_Application* appl=reinterpret_cast<GL_Application*>(creation->lpCreateParams);
SetWindowLong(hwnd,GWL_USERDATA,reinterpret_cast<LONG>(appl));
..........
}
else
{
GL_Application* appl=reinterpret_cast<GL_Application*>(user_data);
.............
}
}
/*
reinterpret_cast < type-id > ( expression )
The reinterpret_cast operator allows any pointer to be converted into any other pointer type,
and it allows any integral type to be converted into any pointer type and vice versa.
Misuse of the reinterpret_cast operator can easily be unsafe.
Unless the desired conversion is inherently low-level, you should use one of the other cast operators.
*/
我很纳闷,#ifndef是为了用来防止重复定义的,那么定义的__EXAMPLE_H__这个量究竟是用到哪儿去了,没见到有__EXAMPLE_H__这个头文件啊
还有reinterpret_cast<CREATESTRUCT*>(lparam)中lparam只是窗口类中的一个消息,通过这个消息就能获得整个窗口类的指针吗?
[解决办法]
宏是预编译时期处理的
不是编译期。
[解决办法]
#ifndef...#define是宏定义,在预编译时期处理。_EXAMPLE_H__是一个宏,不是头文件。
reinterpret_cast<CREATESTRUCT*>(lparam)中lparam是一个指针,利用消息传递过来的。所以用指针转换就可以获得到了整个窗口的指针。
吧里的哥哥姐姐们帮忙看一下代码解决方法
吧里的哥哥姐姐们帮忙看一下代码[codeC/C++][/code]#ifndef__EXAMPLE_H__//这个名称是为了防止重复定义,
