下面是错误: 1>c:\users\ben\documents\visual studio 2010\projects\opengl_learning\opengl_learning_without_glut\openglcontext.cpp(18):error C2533:'OpenGLContext::{ctor}‘:构造函数不允许返回类型
下面是错误所在的代码块,特别是错误来自默认构造函数:
#include <Windows.h>
#include <iostream>
#include "OpenGLContext.h"
/**
Default constructor for the OpenGLContext class. At this stage it does nothing
but you can put anything you want here.
*/
OpenGLContext::OpenGLContext(void){}
OpenGLContext::OpenGLContext(HWND hwnd) {
createContext(hwnd);
}
/**
Destructor for our OpenGLContext class which will clean up our rendering context
and release the device context from the current window.
*/
OpenGLContext::~OpenGLContext(void) {
wglMakeCurrent(hdc, 0); // Remove the rendering context from our device context
wglDeleteContext(hrc); // Delete our rendering context
ReleaseDC(hwnd, hdc); // Release the device context from our window
}为什么!?
发布于 2011-04-18 19:48:54
很可能您在OpenGLContext的定义之后忘记了一个分号。
class OpenGLContext { /* ... */ } OpenGLContext::OpenGLContext(void) { }这在语法上是有效的。但是由于构造函数没有返回类型,正如消息所说的那样,编译器会抱怨。
发布于 2011-04-18 19:49:41
头文件中类定义后缺少分号
发布于 2011-04-18 19:51:19
打开文件OpenGLContext.h,并确保在OpenGLContext类定义后放置了分号。
https://stackoverflow.com/questions/5702342
复制相似问题